Parser
in package
Parser parses YAML strings to convert them to PHP arrays.
Tags
Table of Contents
- BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?'
- REFERENCE_PATTERN = '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u'
- TAG_PATTERN = '(?P<tag>![\w!.\/:-]+)'
- $currentLine : mixed
- $currentLineNb : mixed
- $filename : mixed
- $lines : mixed
- $locallySkippedLineNumbers : mixed
- $numberOfParsedLines : mixed
- $offset : mixed
- $refs : mixed
- $refsBeingParsed : mixed
- $skippedLineNumbers : mixed
- $totalNumberOfLines : mixed
- parse() : mixed
- Parses a YAML string to a PHP value.
- parseFile() : mixed
- Parses a YAML file into a PHP value.
- cleanup() : string
- Cleanups a YAML string to be parsed.
- consumeWhitespaces() : bool
- doParse() : mixed
- getCurrentLineIndentation() : int
- Returns the current line indentation.
- getLineTag() : string|null
- getNextEmbedBlock() : string
- Returns the next embed block of YAML.
- hasMoreLines() : bool
- 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() : bool
- 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.
- lexInlineMapping() : string
- lexInlineQuotedString() : string
- lexInlineSequence() : string
- lexInlineStructure() : string
- lexUnquotedString() : string
- 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() : string
- 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> +#.*)?'
REFERENCE_PATTERN
public
mixed
REFERENCE_PATTERN
= '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u'
TAG_PATTERN
public
mixed
TAG_PATTERN
= '(?P<tag>![\w!.\/:-]+)'
Properties
$currentLine
private
mixed
$currentLine
= ''
$currentLineNb
private
mixed
$currentLineNb
= -1
$filename
private
mixed
$filename
$lines
private
mixed
$lines
= []
$locallySkippedLineNumbers
private
mixed
$locallySkippedLineNumbers
= []
$numberOfParsedLines
private
mixed
$numberOfParsedLines
= 0
$offset
private
mixed
$offset
= 0
$refs
private
mixed
$refs
= []
$refsBeingParsed
private
mixed
$refsBeingParsed
= []
$skippedLineNumbers
private
mixed
$skippedLineNumbers
= []
$totalNumberOfLines
private
mixed
$totalNumberOfLines
Methods
parse()
Parses a YAML string to a PHP value.
public
parse(string $value, int $flags) : mixed
Parameters
- $value : string
-
A YAML string
- $flags : int
-
A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
Tags
Return values
mixed —parseFile()
Parses a YAML file into a PHP value.
public
parseFile(string $filename, int $flags) : mixed
Parameters
- $filename : string
-
The path to the YAML file to be parsed
- $flags : int
-
A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
Tags
Return values
mixed —cleanup()
Cleanups a YAML string to be parsed.
private
cleanup(string $value) : string
Parameters
- $value : string
-
The input YAML string
Return values
string —consumeWhitespaces()
private
consumeWhitespaces(int &$cursor) : bool
Parameters
- $cursor : int
Return values
bool —doParse()
private
doParse(string $value, int $flags) : mixed
Parameters
- $value : string
- $flags : int
Return values
mixed —getCurrentLineIndentation()
Returns the current line indentation.
private
getCurrentLineIndentation() : int
Return values
int —getLineTag()
private
getLineTag(string $value, int $flags[, bool $nextLineCheck = true ]) : string|null
Parameters
- $value : string
- $flags : int
- $nextLineCheck : bool = true
Return values
string|null —getNextEmbedBlock()
Returns the next embed block of YAML.
private
getNextEmbedBlock([int|null $indentation = null ][, bool $inSequence = false ]) : string
Parameters
- $indentation : int|null = 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
Return values
string —hasMoreLines()
private
hasMoreLines() : bool
Return values
bool —isCurrentLineBlank()
Returns true if the current line is blank.
private
isCurrentLineBlank() : bool
Return values
bool —isCurrentLineComment()
Returns true if the current line is a comment line.
private
isCurrentLineComment() : bool
Return values
bool —isCurrentLineEmpty()
Returns true if the current line is blank or if it is a comment line.
private
isCurrentLineEmpty() : bool
Return values
bool —isCurrentLineLastLineInDocument()
private
isCurrentLineLastLineInDocument() : bool
Return values
bool —isNextLineIndented()
Returns true if the next line is indented.
private
isNextLineIndented() : bool
Return values
bool —isNextLineUnIndentedCollection()
Returns true if the next line starts unindented collection.
private
isNextLineUnIndentedCollection() : bool
Return values
bool —isStringUnIndentedCollectionItem()
Returns true if the string is un-indented collection item.
private
isStringUnIndentedCollectionItem() : bool
Return values
bool —lexInlineMapping()
private
lexInlineMapping(int &$cursor) : string
Parameters
- $cursor : int
Return values
string —lexInlineQuotedString()
private
lexInlineQuotedString(int &$cursor) : string
Parameters
- $cursor : int
Return values
string —lexInlineSequence()
private
lexInlineSequence(int &$cursor) : string
Parameters
- $cursor : int
Return values
string —lexInlineStructure()
private
lexInlineStructure(int &$cursor, string $closingTag) : string
Parameters
- $cursor : int
- $closingTag : string
Return values
string —lexUnquotedString()
private
lexUnquotedString(int &$cursor) : string
Parameters
- $cursor : int
Return values
string —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(int $offset, string $yaml, int $flags) : mixed
Parameters
- $offset : int
- $yaml : string
- $flags : int
Return values
mixed —parseBlockScalar()
Parses a block scalar.
private
parseBlockScalar(string $style[, string $chomping = '' ], int $indentation) : 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
-
The indentation indicator that was used to begin this block scalar
Return values
string —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 Yaml::PARSE_* constants to customize the YAML parser behavior
- $context : string
-
The parser context (either sequence or mapping)
Tags
Return values
mixed —trimTag()
Trim the tag on top of the value.
private
trimTag(string $value) : string
Prevent values such as "!foo {quz: bar}" to be considered as a mapping block.
Parameters
- $value : string