PHP Class Spyc

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: $parser = new Spyc; $array = $parser->load($file);
Show file Open project: mustangostang/spyc Class Usage Examples

Public Properties

Property Type Description
$_nodeId
$setting_dump_force_quotes boolean Setting this to true will force YAMLDump to enclose any string value in quotes. False by default.
$setting_use_syck_is_possible boolean Setting this to true will forse YAMLLoad to use syck_load function when possible. False by default.

Public Methods

Method Description
YAMLDump ( array $array, integer $indent = false, integer $wordwrap = false, integer $no_opening_dashes = false ) : string Dump YAML from PHP array statically
YAMLLoad ( string $input ) : array Load YAML into a PHP array statically
YAMLLoadString ( string $input ) : array Load a string of YAML into a PHP array statically
dump ( array $array, integer $indent = false, integer $wordwrap = false, $no_opening_dashes = false ) : string Dump PHP array to YAML
load ( string $input ) : array Load a valid YAML string to Spyc.
loadFile ( string $file ) : array Load a valid YAML file to Spyc.
revertLiteralPlaceHolder ( $lineArray, $literalBlock )

Private Methods

Method Description
__load ( $input ) LOADING FUNCTIONS
__loadString ( $input )
_doFolding ( $value, $indent ) : string Folds a string of text, if necessary
_doLiteralBlock ( $value, $indent ) : string Creates a literal block for dumping
_dumpNode ( $key, $value, $indent, $previous_key, $first_key, $source_array = null ) : string Returns YAML from a key and a value
_inlineEscape ( $inline ) : array Used in inlines to check for more inlines or quoted strings
_parseLine ( string $line ) : array Parses YAML code and returns an array for a node
_toType ( string $value ) : mixed Finds the type of the passed value, returns the value as the new type.
_yamlize ( $key, $value, $indent, $previous_key, $first_key, $source_array = null ) : string Attempts to convert a key / value array item to YAML
_yamlizeArray ( $array, $indent ) : string Attempts to convert an array to YAML
addArray ( $incoming_data, $incoming_indent )
addArrayInline ( $array, $indent )
addGroup ( $line, $group )
addLiteralLine ( $literalBlock, $line, $literalBlockStyle, $indent )
checkKeysInValue ( $value )
clearBiggerPathValues ( $indent )
coerceValue ( &$value ) Coerce a string into a native type Reference: http://yaml.org/type/bool.html TODO: Use only words from the YAML spec.
getParentPathByIndent ( $indent )
getTranslations ( array $words ) Given a set of words, perform the appropriate translations on them to match the YAML 1.1 specification for type coercing.
greedilyNeedNextLine ( $line )
isArrayElement ( $line )
isComment ( $line )
isEmpty ( $line )
isFalseWord ( $value )
isHashElement ( $line )
isLiteral ( $line )
isNullWord ( $value )
isPlainArray ( $line )
isTranslationWord ( $value )
isTrueWord ( $value )
literalBlockContinues ( $line, $lineIndent )
loadFromSource ( $input )
loadFromString ( $input )
loadWithSource ( $Source )
nodeContainsGroup ( $line )
referenceContentsByAlias ( $alias )
returnArrayElement ( $line )
returnKeyValuePair ( $line )
returnMappedSequence ( $line )
returnMappedValue ( $line )
returnPlainArray ( $line )
startsLiteralBlock ( $line )
startsMappedSequence ( $line )
startsMappedValue ( $line )
stripGroup ( $line, $group )
stripIndent ( $line, $indent )
unquote ( $value )

Method Details

YAMLDump() public static method

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.
public static YAMLDump ( array $array, integer $indent = false, integer $wordwrap = false, integer $no_opening_dashes = false ) : string
$array array PHP array
$indent integer Pass in false to use the default, which is 2
$wordwrap integer Pass in 0 for no wordwrap, false for default (40)
$no_opening_dashes integer Do not start YAML file with "---\n"
return string

YAMLLoad() public static method

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);
public static YAMLLoad ( string $input ) : array
$input string Path of YAML file or string containing YAML
return array

YAMLLoadString() public static method

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);
public static YAMLLoadString ( string $input ) : array
$input string String containing YAML
return array

dump() public method

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.
public dump ( array $array, integer $indent = false, integer $wordwrap = false, $no_opening_dashes = false ) : string
$array array PHP array
$indent integer Pass in false to use the default, which is 2
$wordwrap integer Pass in 0 for no wordwrap, false for default (40)
return string

load() public method

Load a valid YAML string to Spyc.
public load ( string $input ) : array
$input string
return array

loadFile() public method

Load a valid YAML file to Spyc.
public loadFile ( string $file ) : array
$file string
return array

revertLiteralPlaceHolder() public method

public revertLiteralPlaceHolder ( $lineArray, $literalBlock )

Property Details

$_nodeId public property

public $_nodeId

$setting_dump_force_quotes public property

Setting this to true will force YAMLDump to enclose any string value in quotes. False by default.
public bool $setting_dump_force_quotes
return boolean

$setting_use_syck_is_possible public property

Setting this to true will forse YAMLLoad to use syck_load function when possible. False by default.
public bool $setting_use_syck_is_possible
return boolean