Zend_Config_Yaml does not parse embedded PHP #42

Closed
zfbot opened this Issue Apr 5, 2013 · 4 comments

Comments

Projects
None yet
3 participants

zfbot commented Apr 5, 2013

Jira Information

Original Issue:ZF-12487
Issue Type:Bug
Reporter:digitalprecision
Created:12/16/12
Assignee:
Components:Zend_Config

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.

zfbot commented Apr 5, 2013

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF-12487

Known GitHub users mentioned in the original message or comment:
@digitalprecision

froschdesign was assigned Apr 11, 2013

Member

froschdesign commented Jan 3, 2014

We will not add any new features or functionality for ZF1.
Please make your proposal in ZF2. Thanks!

Took over a year to reach this conclusion? Some of us don't have the time nor the money to invest in upgrading zf1 -> zf2.

Member

froschdesign commented Jan 3, 2014

@digitalprecision
Sorry, but it's also my spare time and I get also no money.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment