Documentation

Parser
in package

Parser parses YAML strings to convert them to PHP arrays.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Constants

BLOCK_SCALAR_HEADER_PATTERN  = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?'
TAG_PATTERN  = '(?P<tag>![\w!.\/:-]+)'

Properties

$currentLine  : mixed
$currentLineNb  : mixed
$lines  : mixed
$locallySkippedLineNumbers  : mixed
$offset  : mixed
$refs  : mixed
$skippedLineNumbers  : mixed
$totalNumberOfLines  : mixed

Methods

__construct()  : mixed
parse()  : mixed
Parses a YAML string to a PHP value.
cleanup()  : string
Cleanups a YAML string to be parsed.
doParse()  : mixed
getCurrentLineIndentation()  : int
Returns the current line indentation.
getLineTag()  : mixed
getNextEmbedBlock()  : string
Returns the next embed block of YAML.
getRealCurrentLineNb()  : int
Returns the current line number (takes the offset into account).
isBlockScalarHeader()  : bool
Tests whether or not the current line is the header of a block scalar.
isCurrentLineBlank()  : bool
Returns true if the current line is blank.
isCurrentLineComment()  : bool
Returns true if the current line is a comment line.
isCurrentLineEmpty()  : bool
Returns true if the current line is blank or if it is a comment line.
isCurrentLineLastLineInDocument()  : mixed
isNextLineIndented()  : bool
Returns true if the next line is indented.
isNextLineUnIndentedCollection()  : bool
Returns true if the next line starts unindented collection.
isStringUnIndentedCollectionItem()  : bool
Returns true if the string is un-indented collection item.
moveToNextLine()  : bool
Moves the parser to the next line.
moveToPreviousLine()  : bool
Moves the parser to the previous line.
parseBlock()  : mixed
parseBlockScalar()  : string
Parses a block scalar.
parseValue()  : mixed
Parses a YAML value.
trimTag()  : mixed
Trim the tag on top of the value.

Constants

BLOCK_SCALAR_HEADER_PATTERN

public mixed BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?'

TAG_PATTERN

public mixed TAG_PATTERN = '(?P<tag>![\w!.\/:-]+)'

Properties

$currentLine

private mixed $currentLine = ''

$currentLineNb

private mixed $currentLineNb = -1

$lines

private mixed $lines = array()

$locallySkippedLineNumbers

private mixed $locallySkippedLineNumbers = array()

$offset

private mixed $offset = 0

$refs

private mixed $refs = array()

$skippedLineNumbers

private mixed $skippedLineNumbers = array()

$totalNumberOfLines

private mixed $totalNumberOfLines

Methods

__construct()

public __construct() : mixed

parse()

Parses a YAML string to a PHP value.

public parse(string $value[, int $flags = 0 ]) : mixed
Parameters
$value : string

A YAML string

$flags : int = 0

A bit field of PARSE_* constants to customize the YAML parser behavior

Tags
throws
ParseException

If the YAML is not valid

Return values
mixed

A PHP value

cleanup()

Cleanups a YAML string to be parsed.

private cleanup(string $value) : string
Parameters
$value : string

The input YAML string

Return values
string

A cleaned up YAML string

doParse()

private doParse(mixed $value, mixed $flags) : mixed
Parameters
$value : mixed
$flags : mixed

getCurrentLineIndentation()

Returns the current line indentation.

private getCurrentLineIndentation() : int
Return values
int

The current line indentation

getLineTag()

private getLineTag(mixed $value, mixed $flags[, mixed $nextLineCheck = true ]) : mixed
Parameters
$value : mixed
$flags : mixed
$nextLineCheck : mixed = true

getNextEmbedBlock()

Returns the next embed block of YAML.

private getNextEmbedBlock([int $indentation = null ][, bool $inSequence = false ]) : string
Parameters
$indentation : int = null

The indent level at which the block is to be read, or null for default

$inSequence : bool = false

True if the enclosing data structure is a sequence

Tags
throws
ParseException

When indentation problem are detected

Return values
string

A YAML string

getRealCurrentLineNb()

Returns the current line number (takes the offset into account).

private getRealCurrentLineNb() : int
Return values
int

The current line number

isBlockScalarHeader()

Tests whether or not the current line is the header of a block scalar.

private isBlockScalarHeader() : bool
Return values
bool

isCurrentLineBlank()

Returns true if the current line is blank.

private isCurrentLineBlank() : bool
Return values
bool

Returns true if the current line is blank, false otherwise

isCurrentLineComment()

Returns true if the current line is a comment line.

private isCurrentLineComment() : bool
Return values
bool

Returns true if the current line is a comment line, false otherwise

isCurrentLineEmpty()

Returns true if the current line is blank or if it is a comment line.

private isCurrentLineEmpty() : bool
Return values
bool

Returns true if the current line is empty or if it is a comment line, false otherwise

isCurrentLineLastLineInDocument()

private isCurrentLineLastLineInDocument() : mixed

isNextLineIndented()

Returns true if the next line is indented.

private isNextLineIndented() : bool
Return values
bool

Returns true if the next line is indented, false otherwise

isNextLineUnIndentedCollection()

Returns true if the next line starts unindented collection.

private isNextLineUnIndentedCollection() : bool
Return values
bool

Returns true if the next line starts unindented collection, false otherwise

isStringUnIndentedCollectionItem()

Returns true if the string is un-indented collection item.

private isStringUnIndentedCollectionItem() : bool
Return values
bool

Returns true if the string is un-indented collection item, false otherwise

moveToNextLine()

Moves the parser to the next line.

private moveToNextLine() : bool
Return values
bool

moveToPreviousLine()

Moves the parser to the previous line.

private moveToPreviousLine() : bool
Return values
bool

parseBlock()

private parseBlock(mixed $offset, mixed $yaml, mixed $flags) : mixed
Parameters
$offset : mixed
$yaml : mixed
$flags : mixed

parseBlockScalar()

Parses a block scalar.

private parseBlockScalar(string $style[, string $chomping = '' ][, int $indentation = 0 ]) : string
Parameters
$style : string

The style indicator that was used to begin this block scalar (| or >)

$chomping : string = ''

The chomping indicator that was used to begin this block scalar (+ or -)

$indentation : int = 0

The indentation indicator that was used to begin this block scalar

Return values
string

The text value

parseValue()

Parses a YAML value.

private parseValue(string $value, int $flags, string $context) : mixed
Parameters
$value : string

A YAML value

$flags : int

A bit field of PARSE_* constants to customize the YAML parser behavior

$context : string

The parser context (either sequence or mapping)

Tags
throws
ParseException

When reference does not exist

Return values
mixed

A PHP value

trimTag()

Trim the tag on top of the value.

private trimTag(mixed $value) : mixed

Prevent values such as !foo {quz: bar} to be considered as a mapping block.

Parameters
$value : mixed

        
On this page

Search results