namespace KumamidoriExampleBlogConfig
use SymfonyComponentConfigDefinitionBuilderTreeBuilder;
use SymfonyComponentConfigDefinitionConfigurationInterface;
class BlogConfigTree implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$builder = new TreeBuilder();
$rootNode = $builder->root(‘blog');
$rootNode
->children()
->arrayNode('foo')
->children()
->scalarNode(‘contents_dir’)
->isRequired()
->end()
->end()
->end()
->end()
//
->end();
return $builder;
}
}
blog:
foo:
contents_dir: ‘bar'
class FooModule extends AbstractModule
{
public function configure()
{
$config = include dirname(dirname(__DIR__)) . '/
var/conf/foo.php';
$this->guardInvalid($config);
}
private function guardInvalid($config)
{
assert(!empty($config));
assert(isset($config[‘contents_dir’]));
//
}
}
class FooModule extends AbstractConfigAwareModule
{
public function configure()
{
$this->bind()->annotatedWith(‘app.aaa.bar')-
>toInstance($this->config['bar']['aaa']);
ᴗ

[BEAR.Sunday] Symfony Configコンポーネント統合例の紹介

  • 5.
    namespace KumamidoriExampleBlogConfig use SymfonyComponentConfigDefinitionBuilderTreeBuilder; useSymfonyComponentConfigDefinitionConfigurationInterface; class BlogConfigTree implements ConfigurationInterface { public function getConfigTreeBuilder() { $builder = new TreeBuilder(); $rootNode = $builder->root(‘blog'); $rootNode ->children() ->arrayNode('foo') ->children() ->scalarNode(‘contents_dir’) ->isRequired() ->end() ->end() ->end() ->end() // ->end(); return $builder; } } blog: foo: contents_dir: ‘bar'
  • 7.
    class FooModule extendsAbstractModule { public function configure() { $config = include dirname(dirname(__DIR__)) . '/ var/conf/foo.php'; $this->guardInvalid($config); } private function guardInvalid($config) { assert(!empty($config)); assert(isset($config[‘contents_dir’])); // } } class FooModule extends AbstractConfigAwareModule { public function configure() { $this->bind()->annotatedWith(‘app.aaa.bar')- >toInstance($this->config['bar']['aaa']);
  • 10.