【发布时间】:2016-06-09 18:02:26
【问题描述】:
我正在构建一个扩展来从所有已安装的捆绑包中加载配置文件。
我的扩展看起来像这样:
<?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 上的所有类似问题
更新
【问题讨论】:
-
你的捆绑名称中真的有 BotBot 吗?TheBuggestBotBotExtension?前缀必须完全匹配。
-
是的,包的名称是 TheBuggestBotBotBundle。我尝试使用 the_buggest_bot_bot 作为 symfony 生成,它也不起作用。
-
在你的扩展中粘贴一个 die 语句,只是为了验证它正在被加载。我仍然怀疑它不是。不用说,确保捆绑包也在 AppKernel 中。
-
我在扩展类的加载函数中添加了 die。它以死亡消息退出。所以调用了加载函数