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> +#.*)?'
- TAG_PATTERN = '(?P<tag>![\w!.\/:-]+)'
- $currentLine : mixed
- $currentLineNb : mixed
- $filename : mixed
- $lines : mixed
- $locallySkippedLineNumbers : mixed
- $offset : mixed
- $refs : mixed
- $refsBeingParsed : mixed
- $skippedLineNumbers : mixed
- $totalNumberOfLines : mixed
- __construct() : 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.
- doParse() : mixed
- getCurrentLineIndentation() : int
- Returns the current line indentation.
- getDeprecationMessage() : mixed
- getLineTag() : string|null
- getNextEmbedBlock() : string
- Returns the next embed block of YAML.
- 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
$filename
private
mixed
$filename
$lines
private
mixed
$lines
= []
$locallySkippedLineNumbers
private
mixed
$locallySkippedLineNumbers
= []
$offset
private
mixed
$offset
= 0
$refs
private
mixed
$refs
= []
$refsBeingParsed
private
mixed
$refsBeingParsed
= []
$skippedLineNumbers
private
mixed
$skippedLineNumbers
= []
$totalNumberOfLines
private
mixed
$totalNumberOfLines
Methods
__construct()
public
__construct() : mixed
Return values
mixed —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 PARSE_* constants to customize the YAML parser behavior
Tags
Return values
mixed —A PHP value
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 PARSE_* constants to customize the YAML parser behavior
Tags
Return values
mixed —The YAML converted to 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
Return values
mixed —getCurrentLineIndentation()
Returns the current line indentation.
private
getCurrentLineIndentation() : int
Return values
int —The current line indentation
getDeprecationMessage()
private
getDeprecationMessage(mixed $message) : mixed
Parameters
- $message : mixed
Return values
mixed —getLineTag()
private
getLineTag(mixed $value, mixed $flags[, mixed $nextLineCheck = true ]) : string|null
Parameters
- $value : mixed
- $flags : mixed
- $nextLineCheck : mixed = true
Return values
string|null —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
Return values
string —A YAML string
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
Return values
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
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 —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
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