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
$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');
$yml would contain the following
---
test:
key: value
test2: test
Dumping array to yml file
$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');
A file named test.yml would be created and would contain the following
---
test:
key: value
test2: test
++ Loading
Loading and parsing data from a yml file to a php array
$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);
The print_r() would output the following
Array
(
[test] => Array
(
[key] => value
)
[test2] => test
)