Stopping Symfony 2 configuration processor from adding an empty array? -
with following configuration tree:
$rootnode ->fixxmlconfig('parameter') ->children() ->arraynode('parameters') ->useattributeaskey('name') ->prototype('array') ->children() ->scalarnode('type')->end() ->scalarnode('value')->end() ->end() ->end() ->end() ->end();
... if not specify parameters
key, symfony adding empty array:
$config = $processor->processconfiguration($configuration, array()); var_dump($config); // output array('parameters' => array())
but want parameters
key unset, absent, if there not parameters.
i've tried deleting key (if empty) in beforenormalization
, doesn't work:
$rootnode ->beforenormalization() ->always(function ($v) { if(empty($v['parameters'])) { unset($v['parameters']); } return $v; })
seems empty array before normalization callback never executed.
array node ensure normalized value of configuration key array , nothing else, nothing provided (in case empty array).
instead of trying rid of key in returned result of configuration processor, think, make more sense handle config item (which array) after processing done. example, can unset if empty.
$config = $processor->processconfiguration($configuration, array()); if(empty($config['parameters'])) { unset($config['parameters']); }
Comments
Post a Comment