Documentation

Parser
in package

Parser parses YAML strings to convert them to PHP arrays.

Tags
author

Fabien Potencier fabien@symfony.com

final

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  : string
$currentLineNb  : int
$filename  : string|null
$lines  : array<string|int, mixed>
$locallySkippedLineNumbers  : array<string|int, mixed>
$numberOfParsedLines  : int
$offset  : int
$refs  : array<string|int, mixed>
$refsBeingParsed  : array<string|int, mixed>
$skippedLineNumbers  : array<string|int, mixed>
$totalNumberOfLines  : int|null
parse()  : mixed
Parses a YAML string to a PHP value.
parseFile()  : mixed
Parses a YAML file into a PHP value.
cleanup()  : string
consumeWhitespaces()  : bool
doParse()  : mixed
getCurrentLineIndentation()  : int
getLineTag()  : string|null
getNextEmbedBlock()  : string
Returns the next embed block of YAML.
hasMoreLines()  : bool
isCurrentLineBlank()  : bool
isCurrentLineComment()  : bool
isCurrentLineEmpty()  : bool
isCurrentLineLastLineInDocument()  : bool
isNextLineIndented()  : bool
Returns true if the next line is indented.
isNextLineUnIndentedCollection()  : bool
isStringUnIndentedCollectionItem()  : bool
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 string $currentLine = ''

$currentLineNb

private int $currentLineNb = -1

$filename

private string|null $filename = null

$lines

private array<string|int, mixed> $lines = []

$locallySkippedLineNumbers

private array<string|int, mixed> $locallySkippedLineNumbers = []

$numberOfParsedLines

private int $numberOfParsedLines = 0

$refs

private array<string|int, mixed> $refs = []

$refsBeingParsed

private array<string|int, mixed> $refsBeingParsed = []

$skippedLineNumbers

private array<string|int, mixed> $skippedLineNumbers = []

$totalNumberOfLines

private int|null $totalNumberOfLines = null

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 PARSE_* constants to customize the YAML parser behavior

Tags
throws
ParseException

If the YAML is not valid

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 PARSE_* constants to customize the YAML parser behavior

Tags
throws
ParseException

If the file could not be read or the YAML is not valid

Return values
mixed

cleanup()

private cleanup(string $value) : string
Parameters
$value : 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()

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
throws
ParseException

When indentation problem are detected

Return values
string

hasMoreLines()

private hasMoreLines() : bool
Return values
bool

isCurrentLineBlank()

private isCurrentLineBlank() : bool
Return values
bool

isCurrentLineComment()

private isCurrentLineComment() : bool
Return values
bool

isCurrentLineEmpty()

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()

private isNextLineUnIndentedCollection() : bool
Return values
bool

isStringUnIndentedCollectionItem()

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 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

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
string

Search results