Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Symfony2 array options config.yml parsing
my_root:
payment_providers:
- { payment_provider: 'abcd', name: 'Paypal' }
- { payment_provider: 'xyzt', name: 'Authorize.net' }
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_root');
$rootNode
->children()
->arrayNode('payment_providers')
->prototype('array')
->children()
->scalarNode('payment_provider')->end()
->scalarNode('name')->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
Array
(
[payment_providers] => Array
(
[0] => Array
(
[payment_provider] => abcd
[name] => Paypal
)
[1] => Array
(
[payment_provider] => xyzt
[name] => Authorize.net
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment