68 lines
1.6 KiB
Plaintext
68 lines
1.6 KiB
Plaintext
The parser is built to allow dumping and loading from many different formats. Currently xml and yml are the only drivers but later other file formats such as csv may be added. You can specify the data to load/dump in with the $type argument on dump() and load()
|
|
|
|
++ Dumping
|
|
|
|
Dumping array to yml variable
|
|
|
|
<code type="php">
|
|
$array = array('test' => array('key' => 'value'), 'test2' => 'test');
|
|
|
|
// Dump the array to yml and return, set to $yml(does not write to file). Replace null with a path to a yml file if you wish to write to disk
|
|
$yml = Doctrine_Parser::dump($array, 'yml');
|
|
</code>
|
|
|
|
$yml would contain the following
|
|
<code type="yaml">
|
|
---
|
|
test:
|
|
key: value
|
|
test2: test
|
|
</code>
|
|
|
|
|
|
Dumping array to yml file
|
|
|
|
<code type="php">
|
|
$array = array('test' => array('key' => 'value'), 'test2' => 'test');
|
|
|
|
// Dump the above array to test.yml using yml parser
|
|
Doctrine_Parser::dump($array, 'yml', 'test.yml');
|
|
</code>
|
|
|
|
A file named test.yml would be created and would contain the following
|
|
<code type="yaml">
|
|
---
|
|
test:
|
|
key: value
|
|
test2: test
|
|
</code>
|
|
|
|
++ Loading
|
|
|
|
Loading and parsing data from a yml file to a php array
|
|
|
|
<code type="php">
|
|
$array = array('test' => array('key' => 'value'), 'test2' => 'test');
|
|
|
|
// We dump the above array to test.yml using the yml parser dumper
|
|
Doctrine_Parser::dump($array, 'yml', 'test.yml');
|
|
|
|
// Now we reload that dumped yaml file back to the original array format using the yml parser loder
|
|
$array = Doctrine_Parser::load('test.yml', 'yml');
|
|
|
|
print_r($array);
|
|
</code>
|
|
|
|
The print_r() would output the following
|
|
|
|
<code>
|
|
Array
|
|
(
|
|
[test] => Array
|
|
(
|
|
[key] => value
|
|
)
|
|
|
|
[test2] => test
|
|
)
|
|
</code> |