首页 文章

Symfony3:没有能够加载配置的扩展

提问于
浏览
0

我正在构建一个扩展来从所有已安装的bundle加载配置文件 .

我的扩展看起来像这样:

<?php

namespace TheBuggestBot\BotBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
 */
class TheBuggestBotBotExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

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

我做了我从symfony文档书和网页上读到的所有内容 . 什么都没有帮助我......

这是我的DependencyInjection / Configuration.php文件:

<?php

namespace TheBuggestBot\BotBundle\DependencyInjection;

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

/**
 * This is the class that validates and merges configuration from your app/config files.
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('the_buggest_bot_bot');

        $rootNode
            ->children()
                ->arrayNode('ircbot')
                    ->children()
                        ->scalarNode('server')->end()
                        ->integerNode('port')->end()
                        ->scalarNode('username')->end()
                        ->scalarNode('password')->end()
                        ->scalarNode('chanel')->end()
                    ->end()
                ->end()
            ->end()
        ;


        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        return $treeBuilder;
    }
}

我的资源/ config / config.yml:

the_buggest_bot_bot:
    ircbot:
        server:   ""
        port:     6667
        username: ""
        password: ""
        chanel:   ""

错误是:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]                                           
  There is no extension able to load the configuration for "thebuggestbot" (in /home/dm3ch/TheBuggestBot/test/src/The  
  BuggestBot/BotBundle/DependencyInjection/../Resources/config/config.yml). Looked for namespace "thebuggestbot", fou  
  nd none

附:我已经阅读了Stack Overflow上的所有类似问题

Updated

1 回答

  • 0

    我有同样的问题,并解决它 .

    要注册扩展,您需要为bundle和扩展名指定相同的名称 . 因此,如果要将扩展名设置为 the_buggest_bot_bot ,则扩展名文件必须命名为 TheBuggestBotBotExtention ,并且bundle必须命名为 TheBuggestBotBotBundle .

    或者,如果您不想更改Bundle名称,则必须将扩展名重命名为与bundle相同的名称 . 或者您可以手动注册扩展名:

    class TheBuggestBotBotBundle extends Bundle
    {
    
      public function getContainerExtension()
      {
        if ($this->extension === null) {
            $this->extension = new TheBuggestBotBotExtension();
        }
    
        return $this->extension;
      }
    }
    

相关问题