我正在尝试在包中加载自定义 YAML 配置文件,该文件出错,说:
没有扩展能够加载配置
自定义 YAML 配置文件:
#AppBundle/Resources/config/myconfig.yml
myapp: myvalue
配置文件:
//AppBundle/DependencyInjection/MyConfiguration.php
namespace AppBundle\DependencyInjection;
use ...
class MyConfiguration implements ConfigurationInterface {
public function getConfigTreeBuilder() {
$treeBuilder = new TreeBuilder();
$treeBuilder->root('myapp')->end();
return $treeBuilder;
}
}
扩展文件:
//AppBundle/DependencyInjection/AppExtension.php
namespace AppBundle\DependencyInjection;
use ...
class AppExtension extends Extension {
public function load(array $configs, ContainerBuilder $container)
{
$this->processConfiguration(new MyConfiguration(), $configs);
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config')
);
$loader->load('myconfig.yml');
}
}
完整的错误信息:
YamlFileLoader.php 第 399 行中的 InvalidArgumentException:没有扩展能够加载“myapp”的配置(在 C:\my_project\src\AppBundle\DependencyInjection/../Resources/config\myconfig.yml 中)。寻找命名空间“myapp”,没有找到