我正在构建一个扩展来从所有已安装的bundle加载配置文件.
我的扩展看起来像这样:
namespace Acme\MenuBundle\DependencyInjection;
// use ...
use Acme\MenuBundle\DependencyInjection\Configuration;
class AcmeMenuExtension extends Extension {
public function load(array $configs, ContainerBuilder $container) {
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$finder = new \Symfony\Component\Finder\Finder();
$finder
->directories()
->in($container->getParameter('kernel.root_dir') . '/../src/*/*Bundle/Resources')
->path('config');
$possibleLocations = array();
foreach ($finder as $c_dir) {
$possibleLocations[] = $c_dir->getPathName();
}
$loader = new Loader\YamlFileLoader($container, new FileLocator($possibleLocations));
$loader->load('menu.yml');
}
}
Run Code Online (Sandbox Code Playgroud)
然后是我的(非常简单的)Configuration类:我将来会添加一个更复杂的树,但是现在我希望它可以使用它:
namespace Acme\MenuBundle\DependencyInjection;
// use ...
class Configuration implements ConfigurationInterface {
public function getConfigTreeBuilder() {
$treeBuilder = new TreeBuilder();
$rootNode …Run Code Online (Sandbox Code Playgroud)