Created
February 18, 2015 21:10
-
-
Save jaytaph/08906a3f38ca9f0867f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "vendor/autoload.php"; | |
use Symfony\Component\Config; | |
use Symfony\Component\Config\Definition\ConfigurationInterface; | |
use Symfony\Component\Yaml\Yaml; | |
class MyConfig implements ConfigurationInterface | |
{ | |
public function getConfigTreeBuilder() | |
{ | |
$treeBuilder = new Config\Definition\Builder\TreeBuilder(); | |
$rootNode = $treeBuilder->root('config'); | |
$rootNode | |
->children() | |
->booleanNode('use_mock') | |
->isRequired() | |
->cannotBeEmpty() | |
->end() | |
->scalarNode('foo') | |
->end() | |
->end() | |
; | |
return $treeBuilder; | |
} | |
} | |
$yamlValues = Yaml::parse(file_get_contents('test.yml')); | |
$processor = new Config\Definition\Processor(); | |
$config = $processor->processConfiguration(new MyConfig(), $yamlValues); | |
// Throws: | |
// PHP Fatal error: Uncaught exception 'Symfony\Component\Config\Definition\Exception\InvalidConfigurationException' with | |
// message 'The path "config.use_mock" cannot contain an empty value, but got false.' in | |
// .../vendor/symfony/config/Symfony/Component/Config/Definition/VariableNode.php:88 | |
var_dump($config); | |
/** test.yml: | |
* config: | |
use_mock: false | |
foo: bar | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment