Parser
in package
Parser parses YAML strings to convert them to PHP arrays.
Tags
Table of Contents
Constants
- BLOCK_SCALAR_HEADER_PATTERN : mixed = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\...
- DEFAULT_MAX_ALIASES_FOR_COLLECTIONS : mixed = 128
- DEFAULT_MAX_NESTING_LEVEL : mixed = 128
- REFERENCE_PATTERN : mixed = '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u'
- TAG_PATTERN : mixed = '(?P<tag>![\w!.\/:-]+)'
- MAX_COPIED_BYTES : mixed = 8192
- MAX_COPIED_EMPTY_LINES : mixed = 8
Properties
- $commentIndentations : array<string|int, mixed>
- $currentLine : string
- $currentLineNb : int
- $filename : string|null
- $lines : array<string|int, mixed>
- $linesIndentation : int
- $linesIndentations : array<string|int, mixed>|null
- $linesOffset : int
- $locallySkippedLineNumbers : array<string|int, mixed>
- $nextLineNumbers : array<string|int, mixed>|null
- $numberOfParsedLines : int
- $offset : int
- $refs : array<string|int, mixed>
- $refsBeingParsed : array<string|int, mixed>
- $replacedLines : array<string|int, mixed>
- $skippedLineNumbers : array<string|int, mixed>
- $state : ParserState|null
- $totalNumberOfLines : int|null
Methods
- __construct() : mixed
- parse() : mixed
- Parses a YAML string to a PHP value.
- parseFile() : mixed
- Parses a YAML file into a PHP value.
- cleanup() : string
- consumeWhitespaces() : bool
- createBlock() : array<string|int, mixed>
- Describes the lines of a nested block, so that they are read in place.
- doLexInlineStructure() : string
- doParse() : mixed
- getBlockLine() : string
- Returns a line of a nested block as getNextEmbedBlock() reads it.
- getBlockText() : string
- Returns the text of a nested block, or only its first line that is neither empty nor a comment.
- getCurrentLineIndentation() : int
- getLine() : string
- getLines() : array<string|int, mixed>
- getLineTag() : string|null
- getNextContentLineNumber() : int
- Returns the number of the first line from the given one that is neither empty nor a comment.
- getNextEmbedBlock() : string|array<string|int, mixed>
- Returns the next embed block of YAML.
- getState() : ParserState
- hasMoreLines() : bool
- indexLines() : void
- Indexes the blank and comment lines, so that nested blocks can skip them.
- isCurrentLineBlank() : bool
- isCurrentLineComment() : bool
- isCurrentLineEmpty() : bool
- isCurrentLineLastLineInDocument() : bool
- isNextLineInBlockScalar() : bool
- Tells whether the next line belongs to a block scalar whose header ends the given value.
- isNextLineIndented() : bool
- Returns true if the next line is indented.
- isNextLineUnIndentedCollection() : bool
- isStringUnIndentedCollectionItem() : bool
- lexInlineAnchorOrAlias() : string
- lexInlineMapping() : string
- lexInlineQuotedString() : string
- lexInlineSequence() : string
- lexInlineStructure() : string
- lexUnquotedString() : string
- moveAnchorBeforeTag() : string
- Turns "!tag &anchor value" into "&anchor !tag value", as both orders are allowed.
- 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.
- prependLine() : string|array<string|int, mixed>
- readBlock() : void
- Reads a nested block in place, as cleanup() would have left it.
- removeLeadingLines() : string
- skipLines() : void
- trimTag() : string
- Trim the tag on top of the value.
- useBlock() : void
Constants
BLOCK_SCALAR_HEADER_PATTERN
public
mixed
BLOCK_SCALAR_HEADER_PATTERN
= '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments>[ \t]+#.*)?'
DEFAULT_MAX_ALIASES_FOR_COLLECTIONS
public
mixed
DEFAULT_MAX_ALIASES_FOR_COLLECTIONS
= 128
DEFAULT_MAX_NESTING_LEVEL
public
mixed
DEFAULT_MAX_NESTING_LEVEL
= 128
REFERENCE_PATTERN
public
mixed
REFERENCE_PATTERN
= '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u'
TAG_PATTERN
public
mixed
TAG_PATTERN
= '(?P<tag>![\w!.\/:-]+)'
MAX_COPIED_BYTES
private
mixed
MAX_COPIED_BYTES
= 8192
MAX_COPIED_EMPTY_LINES
private
mixed
MAX_COPIED_EMPTY_LINES
= 8
Properties
$commentIndentations
private
array<string|int, mixed>
$commentIndentations
= []
$currentLine
private
string
$currentLine
= ''
$currentLineNb
private
int
$currentLineNb
= -1
$filename
private
string|null
$filename
= null
$lines
private
array<string|int, mixed>
$lines
= []
$linesIndentation
private
int
$linesIndentation
= 0
$linesIndentations
private
array<string|int, mixed>|null
$linesIndentations
= null
$linesOffset
private
int
$linesOffset
= 0
$locallySkippedLineNumbers
private
array<string|int, mixed>
$locallySkippedLineNumbers
= []
$nextLineNumbers
private
array<string|int, mixed>|null
$nextLineNumbers
= null
$numberOfParsedLines
private
int
$numberOfParsedLines
= 0
$offset
private
int
$offset
= 0
$refs
private
array<string|int, mixed>
$refs
= []
$refsBeingParsed
private
array<string|int, mixed>
$refsBeingParsed
= []
$replacedLines
private
array<string|int, mixed>
$replacedLines
= []
$skippedLineNumbers
private
array<string|int, mixed>
$skippedLineNumbers
= []
$state
private
ParserState|null
$state
= null
$totalNumberOfLines
private
int|null
$totalNumberOfLines
= null
Methods
__construct()
public
__construct([int $maxNestingLevel = self::DEFAULT_MAX_NESTING_LEVEL ][, int $maxAliasesForCollections = self::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS ]) : mixed
Parameters
- $maxNestingLevel : int = self::DEFAULT_MAX_NESTING_LEVEL
- $maxAliasesForCollections : int = self::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS
parse()
Parses a YAML string to a PHP value.
public
parse(string $value[, Yaml::PARSE_*> $flags = 0 ]) : mixed
Parameters
- $value : string
-
A YAML string
- $flags : Yaml::PARSE_*> = 0
-
A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
Tags
parseFile()
Parses a YAML file into a PHP value.
public
parseFile(string $filename[, Yaml::PARSE_*> $flags = 0 ]) : mixed
Parameters
- $filename : string
-
The path to the YAML file to be parsed
- $flags : Yaml::PARSE_*> = 0
-
A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
Tags
cleanup()
private
cleanup(string $value[, bool|null &$hasContentOnStartMarkerLine = null ]) : string
Parameters
- $value : string
- $hasContentOnStartMarkerLine : bool|null = null
Return values
stringconsumeWhitespaces()
private
consumeWhitespaces(int &$cursor) : bool
Parameters
- $cursor : int
Return values
boolcreateBlock()
Describes the lines of a nested block, so that they are read in place.
private
createBlock(int $firstLineNumber, int $lastLineNumber, int $indentation, string $firstLine) : array<string|int, mixed>
Parameters
- $firstLineNumber : int
- $lastLineNumber : int
- $indentation : int
- $firstLine : string
Return values
array<string|int, mixed>doLexInlineStructure()
private
doLexInlineStructure(int &$cursor, string $closingTag[, bool $consumeUntilEol = true ]) : string
Parameters
- $cursor : int
- $closingTag : string
- $consumeUntilEol : bool = true
Return values
stringdoParse()
private
doParse(string|array<string|int, mixed> $value, int $flags) : mixed
Parameters
- $value : string|array<string|int, mixed>
- $flags : int
getBlockLine()
Returns a line of a nested block as getNextEmbedBlock() reads it.
private
getBlockLine(string $line, int|null $indentation) : string
Parameters
- $line : string
- $indentation : int|null
Return values
stringgetBlockText()
Returns the text of a nested block, or only its first line that is neither empty nor a comment.
private
getBlockText(array<string|int, mixed> $block[, bool $firstContentLineOnly = false ]) : string
Parameters
- $block : array<string|int, mixed>
- $firstContentLineOnly : bool = false
Return values
stringgetCurrentLineIndentation()
private
getCurrentLineIndentation() : int
Return values
intgetLine()
private
getLine(int $lineNumber) : string
Parameters
- $lineNumber : int
Return values
stringgetLines()
private
getLines() : array<string|int, mixed>
Return values
array<string|int, mixed>getLineTag()
private
getLineTag(string $value, int $flags[, bool $nextLineCheck = true ]) : string|null
Parameters
- $value : string
- $flags : int
- $nextLineCheck : bool = true
Return values
string|nullgetNextContentLineNumber()
Returns the number of the first line from the given one that is neither empty nor a comment.
private
getNextContentLineNumber(int $lineNumber) : int
Parameters
- $lineNumber : int
Return values
intgetNextEmbedBlock()
Returns the next embed block of YAML.
private
getNextEmbedBlock([int|null $indentation = null ][, bool $inSequence = false ]) : string|array<string|int, mixed>
A long block, or a block that contains many empty or comment lines, is returned as an array that describes the lines to read in place.
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|array<string|int, mixed>getState()
private
getState() : ParserState
Return values
ParserStatehasMoreLines()
private
hasMoreLines() : bool
Return values
boolindexLines()
Indexes the blank and comment lines, so that nested blocks can skip them.
private
indexLines() : void
A comment line points to the next line that is not a comment, any other line to the next content line.
isCurrentLineBlank()
private
isCurrentLineBlank() : bool
Return values
boolisCurrentLineComment()
private
isCurrentLineComment() : bool
Return values
boolisCurrentLineEmpty()
private
isCurrentLineEmpty() : bool
Return values
boolisCurrentLineLastLineInDocument()
private
isCurrentLineLastLineInDocument() : bool
Return values
boolisNextLineInBlockScalar()
Tells whether the next line belongs to a block scalar whose header ends the given value.
private
isNextLineInBlockScalar(string $value) : bool
Unlike isNextLineIndented(), empty and comment-like lines are not skipped, as they can be part of the block scalar.
Parameters
- $value : string
Return values
boolisNextLineIndented()
Returns true if the next line is indented.
private
isNextLineIndented() : bool
Return values
boolisNextLineUnIndentedCollection()
private
isNextLineUnIndentedCollection() : bool
Return values
boolisStringUnIndentedCollectionItem()
private
isStringUnIndentedCollectionItem() : bool
Return values
boollexInlineAnchorOrAlias()
private
lexInlineAnchorOrAlias(int &$cursor) : string
Parameters
- $cursor : int
Return values
stringlexInlineMapping()
private
lexInlineMapping([int &$cursor = 0 ][, bool $consumeUntilEol = true ]) : string
Parameters
- $cursor : int = 0
- $consumeUntilEol : bool = true
Return values
stringlexInlineQuotedString()
private
lexInlineQuotedString([int &$cursor = 0 ]) : string
Parameters
- $cursor : int = 0
Return values
stringlexInlineSequence()
private
lexInlineSequence([int &$cursor = 0 ][, bool $consumeUntilEol = true ]) : string
Parameters
- $cursor : int = 0
- $consumeUntilEol : bool = true
Return values
stringlexInlineStructure()
private
lexInlineStructure(int &$cursor, string $closingTag[, bool $consumeUntilEol = true ]) : string
Parameters
- $cursor : int
- $closingTag : string
- $consumeUntilEol : bool = true
Return values
stringlexUnquotedString()
private
lexUnquotedString(int &$cursor) : string
Parameters
- $cursor : int
Return values
stringmoveAnchorBeforeTag()
Turns "!tag &anchor value" into "&anchor !tag value", as both orders are allowed.
private
moveAnchorBeforeTag(string $value) : string
Built-in tags are left alone: "!!str &foo" is the "&foo" string, as in flow collections.
Parameters
- $value : string
Return values
stringmoveToNextLine()
Moves the parser to the next line.
private
moveToNextLine() : bool
Return values
boolmoveToPreviousLine()
Moves the parser to the previous line.
private
moveToPreviousLine() : bool
Return values
boolparseBlock()
private
parseBlock(int $offset, string|array<string|int, mixed> $yaml, int $flags) : mixed
Parameters
- $offset : int
- $yaml : string|array<string|int, mixed>
- $flags : int
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
stringparseValue()
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
prependLine()
private
prependLine(string $line, string|array<string|int, mixed> $block) : string|array<string|int, mixed>
Parameters
- $line : string
- $block : string|array<string|int, mixed>
Return values
string|array<string|int, mixed>readBlock()
Reads a nested block in place, as cleanup() would have left it.
private
readBlock(array<string|int, mixed> $block) : void
Parameters
- $block : array<string|int, mixed>
removeLeadingLines()
private
removeLeadingLines(string $pattern, string $value) : string
Parameters
- $pattern : string
- $value : string
Return values
stringskipLines()
private
skipLines(int $count) : void
Parameters
- $count : int
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
Return values
stringuseBlock()
private
useBlock(array<string|int, mixed> $block) : void
Parameters
- $block : array<string|int, mixed>