Skip to content

Instantly share code, notes, and snippets.

@christeredvartsen
Last active February 14, 2017 11:55
Show Gist options
  • Save christeredvartsen/5b576116f69ff3ad82bfb8a2de395a32 to your computer and use it in GitHub Desktop.
Save christeredvartsen/5b576116f69ff3ad82bfb8a2de395a32 to your computer and use it in GitHub Desktop.
Build a free-form config definition with default values with Symfony\Component\Config
<?php
// $builder is an instance of Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition
$builder
->children()
->arrayNode('params')
->info('Arbitrary key => value configuration')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end();
/* When dumped as YAML I would like my config to look something like this:
*
* params:
* key1: value1
* key2: value2
*
* Then a user can add the following config:
*
* params:
* key2: some value
* key3: value3
*
* Which would result in the following configuration:
*
* params:
* key1: value1
* key2: some value
* key3: value3
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment