mediatekformation

YamlSourceManipulator
in package

A class that modifies YAML source, while keeping comments & formatting.

This is designed to work for the most common syntaxes, but not all YAML syntaxes. If content cannot be updated safely, an exception is thrown.

Table of Contents

ARRAY_FORMAT_INLINE  = 'inline'
ARRAY_FORMAT_MULTILINE  = 'multi'
ARRAY_TYPE_HASH  = 'hash'
ARRAY_TYPE_SEQUENCE  = 'sequence'
COMMENT_PLACEHOLDER_VALUE  = '__COMMENT__'
EMPTY_LINE_PLACEHOLDER_VALUE  = '__EMPTY_LINE__'
UNSET_KEY_FLAG  = '__MAKER_VALUE_UNSET'
$arrayFormatForDepths  : mixed
$arrayTypeForDepths  : mixed
$contents  : mixed
$currentData  : mixed
$currentPath  : mixed
$currentPosition  : mixed
$depth  : mixed
$indentationForDepths  : mixed
$logger  : LoggerInterface|null
$previousPath  : mixed
__construct()  : mixed
createCommentLine()  : string
createEmptyLine()  : string
getContents()  : string
getData()  : array<string|int, mixed>
setData()  : mixed
setLogger()  : mixed
addNewKeyToYaml()  : mixed
Adds a new key to current position in the YAML.
advanceBeyondEndOfPreviousKey()  : mixed
advanceBeyondKey()  : mixed
advanceBeyondMultilineArrayLastItem()  : mixed
advanceBeyondValue()  : mixed
advanceBeyondWhitespace()  : mixed
advanceCurrentPosition()  : mixed
advanceToEndOfLine()  : mixed
appendToArrayAtCurrentPath()  : array<string|int, mixed>
Adds a new item (with the given key) to the $data array at the correct position.
changeValueInYaml()  : mixed
Replaces the value at the current position with this value.
convertToYaml()  : mixed
decrementDepth()  : mixed
findEndPositionOfValue()  : mixed
findNextLineBreak()  : mixed
findPositionOfMultilineCharInLine()  : int|null
findPositionOfNextCharacter()  : mixed
Advance until you find *one* of the characters in $chars.
getCurrentData()  : mixed
Returns the value in the current data that is currently being looked at.
getCurrentIndentation()  : string
getCurrentLine()  : mixed
getEndOfKeyPosition()  : mixed
getEndOfPreviousKeyPosition()  : int
Finds the end position of the key that comes *before* this key.
getKeyRegex()  : mixed
getPreferredIndentationSize()  : int
Try to guess a preferred indentation level.
getPreviousLine()  : mixed
guessNextArrayTypeAndAdvance()  : string
Attempts to guess if the array at the current position is a multi-line array or an inline array.
indentMultilineYamlArray()  : string
Takes an unindented multi-line YAML string and indents it so it can be inserted into the current position.
isCharLineBreak()  : bool
isCurrentArrayMultiline()  : bool
isCurrentArraySequence()  : bool
isCurrentLineComment()  : bool
isEOF()  : mixed
isFinalLineComment()  : bool
isHash()  : bool
Duplicated from Symfony's Inline::isHash().
isLineComment()  : bool
isMultilineString()  : bool
isPositionAtBeginningOfArray()  : bool
For the array currently being processed, are we currently handling the first key inside of it?
isPreviousLineComment()  : bool
log()  : mixed
manuallyIncrementIndentation()  : mixed
normalizeSequences()  : mixed
removeKeyAtCurrentPath()  : array<string|int, mixed>
removeKeyFromYaml()  : mixed
removeMetadataKeys()  : mixed
replaceSpecialMetadataCharacters()  : mixed
setValueAtCurrentPath()  : mixed
updateContents()  : mixed
updateData()  : mixed

Constants

Properties

Methods

__construct()

public __construct(string $contents) : mixed
Parameters
$contents : string
Return values
mixed —

createCommentLine()

public createCommentLine(string $comment) : string
Parameters
$comment : string
Return values
string —

getData()

public getData() : array<string|int, mixed>
Return values
array<string|int, mixed> —

setData()

public setData(array<string|int, mixed> $newData) : mixed
Parameters
$newData : array<string|int, mixed>
Return values
mixed —

addNewKeyToYaml()

Adds a new key to current position in the YAML.

private addNewKeyToYaml(mixed $key, mixed $value) : mixed

The position should be set right where this new key should be inserted.

Parameters
$key : mixed
$value : mixed
Return values
mixed —

advanceBeyondEndOfPreviousKey()

private advanceBeyondEndOfPreviousKey(mixed $key) : mixed
Parameters
$key : mixed
Return values
mixed —

advanceBeyondKey()

private advanceBeyondKey(mixed $key) : mixed
Parameters
$key : mixed
Return values
mixed —

advanceBeyondMultilineArrayLastItem()

private advanceBeyondMultilineArrayLastItem(array<string|int, mixed> $currentData, array<string|int, mixed> $newData) : mixed
Parameters
$currentData : array<string|int, mixed>
$newData : array<string|int, mixed>
Return values
mixed —

advanceBeyondValue()

private advanceBeyondValue(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed —

advanceBeyondWhitespace()

private advanceBeyondWhitespace() : mixed
Return values
mixed —

advanceCurrentPosition()

private advanceCurrentPosition(int $newPosition) : mixed
Parameters
$newPosition : int
Return values
mixed —

appendToArrayAtCurrentPath()

Adds a new item (with the given key) to the $data array at the correct position.

private appendToArrayAtCurrentPath(mixed $key, mixed $value, array<string|int, mixed> $data) : array<string|int, mixed>

The $data should be the simple array that should be updated and that the current path is pointing to. The current path is used to determine where in the array to put the new item (so that it's placed in the middle when necessary).

Parameters
$key : mixed
$value : mixed
$data : array<string|int, mixed>
Return values
array<string|int, mixed> —

changeValueInYaml()

Replaces the value at the current position with this value.

private changeValueInYaml(mixed $value) : mixed

The position should be set right at the start of this value (i.e. after its key).

Parameters
$value : mixed

The new value to set into YAML

Return values
mixed —

convertToYaml()

private convertToYaml(mixed $data) : mixed
Parameters
$data : mixed
Return values
mixed —

findEndPositionOfValue()

private findEndPositionOfValue(mixed $value[, mixed $offset = null ]) : mixed
Parameters
$value : mixed
$offset : mixed = null
Return values
mixed —

findNextLineBreak()

private findNextLineBreak(int $position) : mixed
Parameters
$position : int
Return values
mixed —

findPositionOfMultilineCharInLine()

private findPositionOfMultilineCharInLine(int $position) : int|null
Parameters
$position : int
Return values
int|null —

findPositionOfNextCharacter()

Advance until you find *one* of the characters in $chars.

private findPositionOfNextCharacter(array<string|int, mixed> $chars) : mixed
Parameters
$chars : array<string|int, mixed>
Return values
mixed —

getCurrentData()

Returns the value in the current data that is currently being looked at.

private getCurrentData(int $limitLevels) : mixed

This could fail if the currentPath is for new data.

Parameters
$limitLevels : int

If set to 1, the data 1 level up will be returned

Return values
mixed —

getCurrentIndentation()

private getCurrentIndentation([int $override = null ]) : string
Parameters
$override : int = null
Return values
string —

getCurrentLine()

private getCurrentLine(int $position) : mixed
Parameters
$position : int
Return values
mixed —

getEndOfKeyPosition()

private getEndOfKeyPosition(mixed $key) : mixed
Parameters
$key : mixed
Return values
mixed —

getEndOfPreviousKeyPosition()

Finds the end position of the key that comes *before* this key.

private getEndOfPreviousKeyPosition(mixed $key) : int
Parameters
$key : mixed
Return values
int —

getKeyRegex()

private getKeyRegex(mixed $key) : mixed
Parameters
$key : mixed
Return values
mixed —

getPreferredIndentationSize()

Try to guess a preferred indentation level.

private getPreferredIndentationSize() : int
Return values
int —

getPreviousLine()

private getPreviousLine(int $position) : mixed
Parameters
$position : int
Return values
mixed —

guessNextArrayTypeAndAdvance()

Attempts to guess if the array at the current position is a multi-line array or an inline array.

private guessNextArrayTypeAndAdvance() : string
Return values
string —

indentMultilineYamlArray()

Takes an unindented multi-line YAML string and indents it so it can be inserted into the current position.

private indentMultilineYamlArray(string $yaml[, int $indentOverride = null ]) : string

Usually an empty line needs to be prepended to this result before adding to the content.

Parameters
$yaml : string
$indentOverride : int = null
Return values
string —

isCharLineBreak()

private isCharLineBreak(string $char) : bool
Parameters
$char : string
Return values
bool —

isCurrentLineComment()

private isCurrentLineComment(int $position) : bool
Parameters
$position : int
Return values
bool —

isEOF()

private isEOF([int $position = null ]) : mixed
Parameters
$position : int = null
Return values
mixed —

isFinalLineComment()

private isFinalLineComment(string $content) : bool
Parameters
$content : string
Return values
bool —

isHash()

Duplicated from Symfony's Inline::isHash().

private isHash(mixed $value) : bool

Returns true if the value must be rendered as a hash, which includes an indexed array, if the indexes are not sequential.

Parameters
$value : mixed
Return values
bool —

isLineComment()

private isLineComment(string $line) : bool
Parameters
$line : string
Return values
bool —

isMultilineString()

private isMultilineString(mixed $value) : bool
Parameters
$value : mixed
Return values
bool —

isPositionAtBeginningOfArray()

For the array currently being processed, are we currently handling the first key inside of it?

private isPositionAtBeginningOfArray() : bool
Return values
bool —

isPreviousLineComment()

private isPreviousLineComment(int $position) : bool
Parameters
$position : int
Return values
bool —

log()

private log(string $message[, mixed $includeContent = false ]) : mixed
Parameters
$message : string
$includeContent : mixed = false
Return values
mixed —

manuallyIncrementIndentation()

private manuallyIncrementIndentation() : mixed
Return values
mixed —

normalizeSequences()

private normalizeSequences(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>
Return values
mixed —

removeKeyAtCurrentPath()

private removeKeyAtCurrentPath(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>
Return values
array<string|int, mixed> —

removeKeyFromYaml()

private removeKeyFromYaml(mixed $key, mixed $currentVal) : mixed
Parameters
$key : mixed
$currentVal : mixed
Return values
mixed —

removeMetadataKeys()

private removeMetadataKeys(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>
Return values
mixed —

replaceSpecialMetadataCharacters()

private replaceSpecialMetadataCharacters() : mixed
Return values
mixed —

setValueAtCurrentPath()

private setValueAtCurrentPath(mixed $value, array<string|int, mixed> $data, int $limitLevels) : mixed
Parameters
$value : mixed
$data : array<string|int, mixed>
$limitLevels : int
Return values
mixed —

updateContents()

private updateContents(string $newContents, array<string|int, mixed> $newData, int $newPosition) : mixed
Parameters
$newContents : string
$newData : array<string|int, mixed>
$newPosition : int
Return values
mixed —

updateData()

private updateData(array<string|int, mixed> $newData) : mixed
Parameters
$newData : array<string|int, mixed>
Return values
mixed —

Search results