2014-03-26 3 views
0

나는 새 번들을 만들고 내 프로젝트에서 만들고 how to expose the configuration의 지침을 따랐다.Symfony 2 with custom config yaml 파일

이 부분은 정상적으로 작동하지만 번들 구성에서 새 yaml 파일 (내 번들 이름을 따서 이름을 바꿔 다른 번들 구성 폴더에 비슷한 이름의 파일을 만들고 병합 할 수 있음)을 추가하려고하면 다음과 같이 입력하십시오.

InvalidArgumentException: There is no extension able to load the configuration for "foo_bar_notify" (in /path/to/symfony/src/Foo/Bar/NotifyBundle/DependencyInjection/../Resources/config/notify.yml). Looked for namespace "foo_bar_notify", found none 

누군가가 내가하시기 바랍니다 놓친 (또는 잘못하고) 것을 지적 할 수 : 동일한 태그 내가 오류가 발생로드의 확장 클래스에이를 추가합니다.

코드 조각;
구성 클래스

public function getConfigTreeBuilder() 
{ 
    $treeBuilder = new TreeBuilder(); 
    $rootNode = $treeBuilder->root('foo_bar_notify'); 

    $rootNode 
     ->children() 
      ->arrayNode('roles') 
       ->requiresAtLeastOneElement() 
       ->prototype('array') 
        ->children() 
         ->scalarNode('name') 
          ->isRequired(true) 
         ->end() 
         ->scalarNode('description') 
         ->end() 
         ->arrayNode('placeholders') 
          ->prototype('scalar')->end() 
         ->end() 
         ->booleanNode('html') 
          ->isRequired() 
          ->defaultValue(true) 
         ->end() 
         ->scalarNode('template') 
          ->isRequired(true) 
         ->end() 
        ->end() 
       ->end() 
      ->end() 
     ->end(); 

    return $treeBuilder; 
} 

확장 클래스

public function load(array $configs, ContainerBuilder $container) 
{ 
    $processor = new Processor(); 
    $configuration = new Configuration(); 
    $config = $processor->processConfiguration($configuration, $configs); 

    $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 
    $loader->load('services.yml'); 
    $loader->load('foo_bar_notify.yml'); 

    $container->setParameter('notify', $config); 
} 

public function getAlias() 
{ 
    return 'foo_bar_notify'; 
} 

홈페이지 구성 파일

foo_bar_notify: 
    roles: 
     software_developer: 
      name: Alice 
      description: Foo 
      placeholders: 
       - $name 
       - $email 
      html: true 
      template: 'some/path' 
     super_developer: 
      name: Malfoy 
      description: bar 
      html: false 
      template: 'some/path/over/here' 

사용자 정의 YAML (notify.yml)

foo_bar_notify: 
    roles: 
     core_developer: 
      name: core 
      html: true 
      template: 'some/path' 

답변

0

this question의 대답을 사용하는 해결책이 있습니다.

내 확장 클래스는 이제 다음과 같습니다.

private $configFileName = 'notify.yml'; 

public function load(array $configs, ContainerBuilder $container) 
{ 
    // see if there are any other notify.yml files defined in other bundles 
    $finder = new \Symfony\Component\Finder\Finder(); 
    $finder 
     ->directories() 
     ->in($container->getParameter('kernel.root_dir') . '/../src/Foo/Bar/*Bundle/Resources') 
     ->path('config'); 

    foreach ($finder as $c_dir) { 
     $absolute_path = $c_dir.'/'.$this->configFileName; 
     if (file_exists($absolute_path)) { 
      $to_add = array_values(Yaml::parse(file_get_contents($absolute_path))); 
      $configs[0] = $this->merge($configs[0], $to_add[0]); 
     } 
    } 

    $processor = new Processor(); 
    $configuration = new Configuration(); 
    $config = $processor->processConfiguration($configuration, $configs); 

    $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 
    $loader->load('services.yml'); 

    // set the processed values as a parameter 
    $container->setParameter('notify', $config); 
} 
+0

안녕하세요! 내가 그 질문을 연결하고 더 나은 해결책을 찾았 : http://stackoverflow.com/a/22667580/309240 – Misiur