2

私はMicroKernelを持つアプリを持っており、アプリケーションがかなり汎用的で、できるだけ外部に設定したいので、SymfonyのTreeBuilderをカスタム設定で使いたいと考えています。私AppKernelsymfony MicroKernelのカスタム設定名前空間を登録します

<?php 
namespace App\DependencyInjection; 

use Symfony\Component\DependencyInjection\ContainerBuilder; 
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; 

class AppExtension extends ConfigurableExtension 
{ 
    // note that this method is called loadInternal and not load 
    protected function loadInternal(array $mergedConfig, ContainerBuilder $container) 
    { 
     dump($mergedConfig); 
    } 

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

<?php 
namespace App\DependencyInjection; 

use Symfony\Component\Config\Definition\Builder\TreeBuilder; 
use Symfony\Component\Config\Definition\ConfigurationInterface; 

class Configuration implements ConfigurationInterface 
{ 
    public function getConfigTreeBuilder() 
    { 
     $treeBuilder = new TreeBuilder(); 
     $rootNode = $treeBuilder->root('research'); 

     // @formatter:off 
     $rootNode 
      ->children() 
       ->arrayNode('questions') 
        ->children() 
         ->integerNode('client_id')->end() 
         ->scalarNode('client_secret')->end() 
        ->end() 
       ->end()// twitter 
      ->end(); 
     // @formatter:on 

     return $treeBuilder; 
    } 
} 

と私AppExtension:私はこのConfigurationクラスを持っている

There is no extension able to load the configuration for "research" 
(in /var/www/html/src/app/config/config.yml). Looked for 
namespace "research", found "framework", "twig", 
"sensio_framework_extra", "web_profiler" 

:私の問題は、私は私のカスタムnamespaceはsymfonyのために登録を取得することはできませんクラス、私はこのような拡張子を初期化しています。結果として私はdump($mergedConfig)から出力を取得します。私research.yml

<?php 
namespace App; 

use App\DependencyInjection\AppExtension; 
use Doctrine\Common\Annotations\AnnotationRegistry; 
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; 
use Symfony\Component\Config\Loader\LoaderInterface; 
use Symfony\Component\DependencyInjection\ContainerBuilder; 
use Symfony\Component\HttpKernel\Kernel; 
use Symfony\Component\Routing\RouteCollectionBuilder; 
use Symfony\Component\Yaml\Exception\ParseException; 
use Symfony\Component\Yaml\Yaml; 

$loader = require __DIR__ . '/../vendor/autoload.php'; 

// auto-load annotations 
AnnotationRegistry::registerLoader(array($loader, 'loadClass')); 

/** 
* Class AppKernel 
*/ 
class AppKernel extends Kernel 
{ 
    use MicroKernelTrait; 

    ... 

    protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) 
    { 
     $researchConfig = Yaml::parse(file_get_contents(__DIR__ . '/config/research.yml')); 
     $appExtension = new AppExtension(); 
     $appExtension->load(researchConfig, $c); 

     $loader->load(__DIR__ . '/config/config.yml'); 
    } 

    ... 
} 

から私のAppExtensionでLLはそれにもかかわらず、私のconfig.ymlはこのように見えるとき、私は上記のエラーを取得:

framework: 
    secret: S0ME_SUPER_SECRET 
    profiler: { only_exceptions: false } 


research: 
    questions: 
     client_id: 2342323423 
     clent_secret: mysecret 

ので、私は、何をすべきかが必要です実際に私の名前空間を登録してください私はそれを正しく上書きすることができますか?または、は外部ベンダーバンドルにを持っていますか?

+0

あなたがやっていることを試したことはありませんが、バンドルを作る必要があると私は確信しています。 1つのバンドルクラスだけが必要です。 – Cerad

+0

はい、sf 3.3まではバンドルでなければなりません。それ以外の場合は認識されません。ありがとうございます – con

答えて

2

バンドルを登録しないため、symfonyがバンドルの設定名前空間を認識しないため、エラーが発生します。

あなたのアプローチでこの問題を解決する方法はありませんが、Appの代わりにAppBundleを作成し、AppBundleをpublic function registerBundles()に登録することをお勧めします。

f.Eを参照してください。一部の定型文ではhttps://github.com/ikoene/symfony-microのようになります。

代わりに、新しいsymfony Flexでプロジェクトをセットアップしようとすることもできます。
これはすでにMicroKernelを使用しています。バンドルレスで、最新の安定版symfony(sf3.3)もサポートしています。
https://symfony.com/doc/current/setup/flex.html#using-symfony-flex-in-new-applications

あなた自身でトラックから何かを構築する必要はありません。

+0

あなたは正しく、バンドルとして構築されています。これは "普通の" symfonyアプリケーションで期待どおりに動作します。しかし、私はフレックスを試していません.. – con

+1

トピックをはずしますが、フレックスでさえも、あなたの研究構成を扱うためにバンドルが必要です。アプリケーション自体はもはやバンドルとして編成する必要はなくなりますが、プラグインの管理用のバンドルはまだあります。 – Cerad

関連する問題