ZF-12487: Zend_Config_Yaml does not parse embedded PHP
Description
In using {{sfYaml::load($fileUri)}} I have become accustomed to embedding PHP code, specifically constants, within my Yaml files. Running {{sfYaml::load}} natively handles the embedded PHP fine, but when I attempt to use Zend_Config_Yaml with 'decoder' passed in as an option, the embedded PHP code gets treated as a string of text.
After looking at the source code, it appears that line: 169 is the culprit. The file_get_contents call parses the yaml file as a string with no regard to embedded php code, instead it should use output buffering like {{sfYaml::load()}} does.
Example:
$config = new Zend_Config_Yaml($fileUri, 'nav', array('yaml_decoder' => array('sfYaml', 'load')));
$nav = new Zend_Navigation($config);
var_dump($nav->toArray());
array (size=1)
'nav' =>
array (size=2)
'Admin' =>
array (size=5)
'groups' => string '<?php echo UserPlugin_Api_Group::ID_ADMIN . PHP_EOL ?>' (length=54)
'render_if' => string 'logged_in' (length=9)
'label' => string 'Admin' (length=5)
'uri' => string '@fakeUri' (length=8)
'pages' =>
Notice the 'groups' line, instead of: {{'groups' => string '<?php echo UserPlugin_Api_Group::ID_ADMIN . PHP_EOL ?>'}}, it should read: {{'groups' => int '1'}}
To maintain the ability to parse embedded PHP code, I'd suggest adding a check to see if the {{yamlDecoder === array(CLASS, 'decode')}}, if so, then use file_get_contents, if not let the passed in callback handle the parsing of the yaml file.
Comments
Posted by Ralph Schindler (ralph) on 2013-04-05T16:07:06.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf1/issues/42