Documentation

Spyc
in package

The Simple PHP YAML Class.

This class can be used to read a YAML file and convert its contents into a PHP array. It currently supports a very limited subsection of the YAML spec.

Usage: $Spyc = new Spyc; $array = $Spyc->load($file); or: $array = Spyc::YAMLLoad($file); or: $array = spyc_load_file($file);

Table of Contents

REMPTY  = "\x00\x00\x00\x00\x00"
$_nodeId  : mixed
$setting_dump_force_quotes  : bool
Setting this to true will force YAMLDump to enclose any string value in quotes. False by default.
$setting_use_syck_is_possible  : bool
Setting this to true will forse YAMLLoad to use syck_load function when possible. False by default.
$_containsGroupAlias  : mixed
$_containsGroupAnchor  : mixed
$_dumpIndent  : mixed
$_dumpWordWrap  : mixed
$delayedPath  : array<string|int, mixed>
Path modifier that should be applied after adding current element.
$indent  : mixed
$LiteralPlaceHolder  : mixed
$path  : mixed
$result  : mixed
$SavedGroups  : mixed
dump()  : string
Dump PHP array to YAML
load()  : array<string|int, mixed>
Load a valid YAML string to Spyc.
loadFile()  : array<string|int, mixed>
Load a valid YAML file to Spyc.
revertLiteralPlaceHolder()  : mixed
YAMLDump()  : string
Dump YAML from PHP array statically
YAMLLoad()  : array<string|int, mixed>
Load YAML into a PHP array statically
YAMLLoadString()  : array<string|int, mixed>
Load a string of YAML into a PHP array statically
_doFolding()  : string
Folds a string of text, if necessary
_doLiteralBlock()  : string
Creates a literal block for dumping
_dumpNode()  : string
Returns YAML from a key and a value
_inlineEscape()  : array<string|int, mixed>
Used in inlines to check for more inlines or quoted strings
_load()  : mixed
_loadString()  : mixed
_parseLine()  : array<string|int, mixed>
Parses YAML code and returns an array for a node
_toType()  : mixed
Finds the type of the passed value, returns the value as the new type.
_yamlize()  : string
Attempts to convert a key / value array item to YAML
_yamlizeArray()  : string
Attempts to convert an array to YAML
addArray()  : mixed
addArrayInline()  : mixed
addGroup()  : mixed
addLiteralLine()  : mixed
checkKeysInValue()  : mixed
clearBiggerPathValues()  : mixed
coerceValue()  : mixed
Coerce a string into a native type Reference: http://yaml.org/type/bool.html TODO: Use only words from the YAML spec.
getParentPathByIndent()  : mixed
getTranslations()  : mixed
Given a set of words, perform the appropriate translations on them to match the YAML 1.1 specification for type coercing.
greedilyNeedNextLine()  : mixed
isArrayElement()  : mixed
isComment()  : mixed
isEmpty()  : mixed
isFalseWord()  : mixed
isHashElement()  : mixed
isLiteral()  : mixed
isNullWord()  : mixed
isPlainArray()  : mixed
isTranslationWord()  : mixed
isTrueWord()  : mixed
literalBlockContinues()  : mixed
loadFromSource()  : mixed
loadFromString()  : mixed
loadWithSource()  : mixed
nodeContainsGroup()  : mixed
referenceContentsByAlias()  : mixed
returnArrayElement()  : mixed
returnKeyValuePair()  : mixed
returnMappedSequence()  : mixed
returnMappedValue()  : mixed
returnPlainArray()  : mixed
startsLiteralBlock()  : mixed
startsMappedSequence()  : mixed
startsMappedValue()  : mixed
stripGroup()  : mixed
stripIndent()  : mixed
unquote()  : mixed

Constants

REMPTY

public mixed REMPTY = "\x00\x00\x00\x00\x00"

Properties

$_nodeId

public mixed $_nodeId

$setting_dump_force_quotes

Setting this to true will force YAMLDump to enclose any string value in quotes. False by default.

public bool $setting_dump_force_quotes = \false

$setting_use_syck_is_possible

Setting this to true will forse YAMLLoad to use syck_load function when possible. False by default.

public bool $setting_use_syck_is_possible = \false

$_containsGroupAlias

private mixed $_containsGroupAlias = \false

$_containsGroupAnchor

private mixed $_containsGroupAnchor = \false

$_dumpIndent

private mixed $_dumpIndent

$_dumpWordWrap

private mixed $_dumpWordWrap

$delayedPath

Path modifier that should be applied after adding current element.

private array<string|int, mixed> $delayedPath = array()

$indent

private mixed $indent

$LiteralPlaceHolder

private mixed $LiteralPlaceHolder = '___YAML_Literal_Block___'

$path

private mixed $path

$result

private mixed $result

$SavedGroups

private mixed $SavedGroups = array()

Methods

dump()

Dump PHP array to YAML

public dump(array<string|int, mixed> $array[, int $indent = false ][, int $wordwrap = false ][, mixed $no_opening_dashes = false ]) : string

The dump method, when supplied with an array, will do its best to convert the array into friendly YAML. Pretty simple. Feel free to save the returned string as tasteful.yaml and pass it around.

Oh, and you can decide how big the indent is and what the wordwrap for folding is. Pretty cool -- just pass in 'false' for either if you want to use the default.

Indent's default is 2 spaces, wordwrap's default is 40 characters. And you can turn off wordwrap by passing in 0.

Parameters
$array : array<string|int, mixed>

PHP array

$indent : int = false

Pass in false to use the default, which is 2

$wordwrap : int = false

Pass in 0 for no wordwrap, false for default (40)

$no_opening_dashes : mixed = false
Tags
access

public

Return values
string

load()

Load a valid YAML string to Spyc.

public load(string $input) : array<string|int, mixed>
Parameters
$input : string
Return values
array<string|int, mixed>

loadFile()

Load a valid YAML file to Spyc.

public loadFile(string $file) : array<string|int, mixed>
Parameters
$file : string
Return values
array<string|int, mixed>

revertLiteralPlaceHolder()

public revertLiteralPlaceHolder(mixed $lineArray, mixed $literalBlock) : mixed
Parameters
$lineArray : mixed
$literalBlock : mixed
Return values
mixed

YAMLDump()

Dump YAML from PHP array statically

public static YAMLDump(array<string|int, mixed>|stdClass $array[, int $indent = false ][, int $wordwrap = false ][, bool $no_opening_dashes = false ]) : string

The dump method, when supplied with an array, will do its best to convert the array into friendly YAML. Pretty simple. Feel free to save the returned string as nothing.yaml and pass it around.

Oh, and you can decide how big the indent is and what the wordwrap for folding is. Pretty cool -- just pass in 'false' for either if you want to use the default.

Indent's default is 2 spaces, wordwrap's default is 40 characters. And you can turn off wordwrap by passing in 0.

Parameters
$array : array<string|int, mixed>|stdClass

PHP array

$indent : int = false

Pass in false to use the default, which is 2

$wordwrap : int = false

Pass in 0 for no wordwrap, false for default (40)

$no_opening_dashes : bool = false

Do not start YAML file with "---\n"

Tags
access

public

Return values
string

YAMLLoad()

Load YAML into a PHP array statically

public static YAMLLoad(string $input) : array<string|int, mixed>

The load method, when supplied with a YAML stream (string or file), will do its best to convert YAML in a file into a PHP array. Pretty simple. Usage: $array = Spyc::YAMLLoad('lucky.yaml'); print_r($array);

Parameters
$input : string

Path of YAML file or string containing YAML

Tags
access

public

Return values
array<string|int, mixed>

YAMLLoadString()

Load a string of YAML into a PHP array statically

public static YAMLLoadString(string $input) : array<string|int, mixed>

The load method, when supplied with a YAML string, will do its best to convert YAML in a string into a PHP array. Pretty simple.

Note: use this function if you don't want files from the file system loaded and processed as YAML. This is of interest to people concerned about security whose input is from a string.

Usage: $array = Spyc::YAMLLoadString("---\n0: hello world\n"); print_r($array);

Parameters
$input : string

String containing YAML

Tags
access

public

Return values
array<string|int, mixed>

_doFolding()

Folds a string of text, if necessary

private _doFolding( $value, mixed $indent) : string
Parameters
$value :

The string you wish to fold

$indent : mixed
Tags
access

private

Return values
string

_doLiteralBlock()

Creates a literal block for dumping

private _doLiteralBlock( $value,  $indent) : string
Parameters
$value :
$indent :

int The value of the indent

Tags
access

private

Return values
string

_dumpNode()

Returns YAML from a key and a value

private _dumpNode( $key,  $value,  $indent[, mixed $previous_key = -1 ], mixed $first_key[, mixed $source_array = null ]) : string
Parameters
$key :

The name of the key

$value :

The value of the item

$indent :

The indent of the current node

$previous_key : mixed = -1
$first_key : mixed
$source_array : mixed = null
Tags
access

private

Return values
string

_inlineEscape()

Used in inlines to check for more inlines or quoted strings

private _inlineEscape(mixed $inline) : array<string|int, mixed>
Parameters
$inline : mixed
Tags
access

private

Return values
array<string|int, mixed>

_load()

private _load(mixed $input) : mixed
Parameters
$input : mixed
Return values
mixed

_loadString()

private _loadString(mixed $input) : mixed
Parameters
$input : mixed
Return values
mixed

_parseLine()

Parses YAML code and returns an array for a node

private _parseLine(string $line) : array<string|int, mixed>
Parameters
$line : string

A line from the YAML file

Tags
access

private

Return values
array<string|int, mixed>

_toType()

Finds the type of the passed value, returns the value as the new type.

private _toType(string $value) : mixed
Parameters
$value : string
Tags
access

private

Return values
mixed

_yamlize()

Attempts to convert a key / value array item to YAML

private _yamlize( $key,  $value,  $indent[, mixed $previous_key = -1 ], mixed $first_key[, mixed $source_array = null ]) : string
Parameters
$key :

The name of the key

$value :

The value of the item

$indent :

The indent of the current node

$previous_key : mixed = -1
$first_key : mixed
$source_array : mixed = null
Tags
access

private

Return values
string

_yamlizeArray()

Attempts to convert an array to YAML

private _yamlizeArray( $array,  $indent) : string
Parameters
$array :

The array you want to convert

$indent :

The indent of the current level

Tags
access

private

Return values
string

addArray()

private addArray(mixed $incoming_data, mixed $incoming_indent) : mixed
Parameters
$incoming_data : mixed
$incoming_indent : mixed
Return values
mixed

addArrayInline()

private addArrayInline(mixed $array, mixed $indent) : mixed
Parameters
$array : mixed
$indent : mixed
Return values
mixed

addGroup()

private addGroup(mixed $line, mixed $group) : mixed
Parameters
$line : mixed
$group : mixed
Return values
mixed

addLiteralLine()

private addLiteralLine(mixed $literalBlock, mixed $line, mixed $literalBlockStyle[, mixed $indent = -1 ]) : mixed
Parameters
$literalBlock : mixed
$line : mixed
$literalBlockStyle : mixed
$indent : mixed = -1
Return values
mixed

checkKeysInValue()

private checkKeysInValue(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

clearBiggerPathValues()

private clearBiggerPathValues(mixed $indent) : mixed
Parameters
$indent : mixed
Return values
mixed

coerceValue()

Coerce a string into a native type Reference: http://yaml.org/type/bool.html TODO: Use only words from the YAML spec.

private coerceValue( &$value) : mixed
Parameters
$value :

The value to coerce

Tags
access

private

Return values
mixed

getParentPathByIndent()

private getParentPathByIndent(mixed $indent) : mixed
Parameters
$indent : mixed
Return values
mixed

getTranslations()

Given a set of words, perform the appropriate translations on them to match the YAML 1.1 specification for type coercing.

private static getTranslations( $words) : mixed
Parameters
$words :

The words to translate

Tags
access

private

Return values
mixed

greedilyNeedNextLine()

private static greedilyNeedNextLine(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isArrayElement()

private isArrayElement(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isComment()

private static isComment(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isEmpty()

private static isEmpty(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isFalseWord()

private isFalseWord(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

isHashElement()

private isHashElement(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isLiteral()

private isLiteral(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isNullWord()

private isNullWord(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

isPlainArray()

private isPlainArray(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

isTranslationWord()

private isTranslationWord(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

isTrueWord()

private isTrueWord(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

literalBlockContinues()

private literalBlockContinues(mixed $line, mixed $lineIndent) : mixed
Parameters
$line : mixed
$lineIndent : mixed
Return values
mixed

loadFromSource()

private loadFromSource(mixed $input) : mixed
Parameters
$input : mixed
Return values
mixed

loadFromString()

private loadFromString(mixed $input) : mixed
Parameters
$input : mixed
Return values
mixed

loadWithSource()

private loadWithSource(mixed $Source) : mixed
Parameters
$Source : mixed
Return values
mixed

nodeContainsGroup()

private nodeContainsGroup(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

referenceContentsByAlias()

private referenceContentsByAlias(mixed $alias) : mixed
Parameters
$alias : mixed
Return values
mixed

returnArrayElement()

private returnArrayElement(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

returnKeyValuePair()

private returnKeyValuePair(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

returnMappedSequence()

private returnMappedSequence(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

returnMappedValue()

private returnMappedValue(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

returnPlainArray()

private returnPlainArray(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

startsLiteralBlock()

private static startsLiteralBlock(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

startsMappedSequence()

private startsMappedSequence(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

startsMappedValue()

private startsMappedValue(mixed $line) : mixed
Parameters
$line : mixed
Return values
mixed

stripGroup()

private stripGroup(mixed $line, mixed $group) : mixed
Parameters
$line : mixed
$group : mixed
Return values
mixed

stripIndent()

private static stripIndent(mixed $line[, mixed $indent = -1 ]) : mixed
Parameters
$line : mixed
$indent : mixed = -1
Return values
mixed

unquote()

private static unquote(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

Search results