1
0
mirror of synced 2024-12-14 23:26:04 +03:00
doctrine2/manual/docs/en/file-parser.txt

68 lines
1.6 KiB
Plaintext
Raw Normal View History

2007-09-20 20:01:33 +04:00
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
2007-09-20 20:11:59 +04:00
$yml = Doctrine_Parser::dump($array, 'yml');
2007-09-20 20:01:33 +04:00
</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
2007-09-20 20:11:59 +04:00
Doctrine_Parser::dump($array, 'yml', 'test.yml');
2007-09-20 20:01:33 +04:00
</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
2007-09-20 20:11:59 +04:00
Doctrine_Parser::dump($array, 'yml', 'test.yml');
2007-09-20 20:01:33 +04:00
// 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>