Yaml dump and parse methods
YAML is a serialization format most useful when human readability
is a consideration. It can be useful for configuration files, as
well as import and export functions.
This file is a front end for a separate YAML package present in the
vendor directory. The intent is to provide a consistent interface
no mater what underlying library is actually used.
At present, this class expects the symfony/yaml package.
Methods |
public
static
|
dump(mixed $var, integer $inline = 4, integer $indent = 4): string|bool
Dump an PHP array as a YAML string
Dump an PHP array as a YAML string
Parameters
$var |
Variable which will be dumped
|
$inline |
Nesting level where you switch to inline YAML
|
$indent |
Number of spaces to indent for nested nodes
|
Returns
YAML string or false on error
|
#
|
public
static
|
load(string $yamlString): array|boolean
Load a YAML string into a PHP array
Load a YAML string into a PHP array
Parameters
$yamlString |
YAML dump string
|
Returns
PHP array or false on error
|
#
|
public
static
|
read(string $yamlFile): array|false
Read a file containing YAML into a PHP array
Read a file containing YAML into a PHP array
Parameters
$yamlFile |
filename of YAML file
|
Returns
PHP array or false on error
|
#
|
public
static
|
save(array $var, string $yamlFile, integer $inline = 4, integer $indent = 4): integer|boolean
Save a PHP array as a YAML file
Save a PHP array as a YAML file
Parameters
$var |
variable which will be dumped
|
$yamlFile |
filename of YAML file
|
$inline |
Nesting level where you switch to inline YAML
|
$indent |
Number of spaces to indent for nested nodes
|
Returns
number of bytes written, or false on error
|
#
|
public
static
|
dumpWrapped(mixed $var, integer $inline = 4, integer $indent = 4): string|boolean
Dump an PHP array as a YAML string with a php wrapper
Dump an PHP array as a YAML string with a php wrapper
The wrap is a php header that surrounds the yaml with section markers,
'---' and '...' along with php comment markers. The php wrapper keeps the
yaml file contents from being revealed by serving the file directly from
a poorly configured server.
Parameters
$var |
Variable which will be dumped
|
$inline |
Nesting level where you switch to inline YAML
|
$indent |
Number of spaces to indent for nested nodes
|
Returns
YAML string or false on error
|
#
|
public
static
|
loadWrapped(string $yamlString): array|boolean
Load a YAML string with a php wrapper into a PHP array
Load a YAML string with a php wrapper into a PHP array
The wrap is a php header that surrounds the yaml with section markers,
'---' and '...' along with php comment markers. The php wrapper keeps the
yaml file contents from being revealed by serving the file directly from
a poorly configured server.
Parameters
$yamlString |
YAML dump string
|
Returns
PHP array or false on error
|
#
|
public
static
|
readWrapped(string $yamlFile): array|false
Read a file containing YAML with a php wrapper into a PHP array
Read a file containing YAML with a php wrapper into a PHP array
The wrap is a php header that surrounds the yaml with section markers,
'---' and '...' along with php comment markers. The php wrapper keeps the
yaml file contents from being revealed by serving the file directly from
a poorly configured server.
Parameters
$yamlFile |
filename of YAML file
|
Returns
PHP array or false on error
|
#
|
public
static
|
saveWrapped(array $var, string $yamlFile, integer $inline = 4, integer $indent = 4): integer|boolean
Save a PHP array as a YAML file with a php wrapper
Save a PHP array as a YAML file with a php wrapper
The wrap is a php header that surrounds the yaml with section markers,
'---' and '...' along with php comment markers. The php wrapper keeps the
yaml file contents from being revealed by serving the file directly from
a poorly configured server.
Parameters
$var |
variable which will be dumped
|
$yamlFile |
filename of YAML file
|
$inline |
Nesting level where you switch to inline YAML
|
$indent |
Number of spaces to indent for nested nodes
|
Returns
number of bytes written, or false on error
|
#
|
protected
static
|
logError(Exception $e)
|
#
|