我正在尝试覆盖 FOSElasticaExtension https://github.com/FriendsOfSymfony/FOSElasticaBundle的部分内容,以通过包继承处理配置和参数略有不同(这里有些描述http://symfony.com/doc/master/cookbook/bundles/覆盖.html )。不幸的是,缺少这方面的文档,并且在尝试覆盖时出现奇怪的错误(例如根本没有注入配置)。
vendor/acme/Acme/ElasticaBundle/AcmeElasticaBundle.php
<?php
namespace Acme\ElasticaBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Extends FOS Elastica bundle.
*/
class AcmeElasticaBundle extends Bundle
{
public function getParent()
{
return 'FOSElasticaBundle';
}
}
vendor/acme/Acme/ElasticaBundle/DependencyInjection/Configuration.php
<?php
namespace Acme\ElasticaBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use FOS\ElasticaBundle\DependencyInjection\Configuration as BaseConfiguration;
class Configuration extends BaseConfiguration
{
}
vendor/acme/Acme/ElasticaBundle/DependencyInjection/AcmeElasticaExtension.php
<?php
namespace Acme\ElasticaBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\FileLocator;
use FOS\ElasticaBundle\DependencyInjection\FOSElasticaExtension as Extension;
/**
* Overrides some parts of FOS Elastica extension.
*/
class AcmeElasticaExtension extends Extension
{
}
app/AppKernel.php
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new FOS\ElasticaBundle\FOSElasticaBundle(),
new Acme\ElasticaBundle\PhoenixElasticaBundle(),
);
}
}
错误:
ErrorException: Notice: Undefined index: indexes in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 367
我没有更改我的配置,所以我不确定可能是什么原因。我认为他们验证配置的代码运行良好并检索值,但MergeExtensionConfigurationPass
似乎与此不正常:
in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 367
at ErrorHandler->handle('8', 'Undefined index: indexes', '/home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php', '367', array('nestings' => array())) in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 367
at Configuration->getNestings() in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 283
at Configuration->getMappingsNode() in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 265
at Configuration->getTypesNode() in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 188
at Configuration->addIndexesSection(object(ArrayNodeDefinition)) in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/Configuration.php line 30
at Configuration->getConfigTreeBuilder() in /home/tatsh/test-site/vendor/symfony/symfony/src/Symfony/Component/Config/Definition/Processor.php line 52
at Processor->processConfiguration(object(Configuration), array(array())) in /home/tatsh/test-site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php line 103
at Extension->processConfiguration(object(Configuration), array(array())) in /home/tatsh/test-site/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/DependencyInjection/FOSElasticaExtension.php line 23
at FOSElasticaExtension->load(array(array()), object(ContainerBuilder)) in /home/tatsh/test-site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php line 42
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in /home/tatsh/test-site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in /home/tatsh/test-site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php line 119
at Compiler->compile(object(ContainerBuilder)) in /home/tatsh/test-site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php line 453
at ContainerBuilder->compile() in /home/tatsh/test-site/app/bootstrap.php.cache line 950
at Kernel->buildContainer() in /home/tatsh/test-site/app/bootstrap.php.cache line 859
at Kernel->initializeContainer() in /home/tatsh/test-site/app/bootstrap.php.cache line 571
at Kernel->boot() in /home/tatsh/test-site/app/bootstrap.php.cache line 614
at Kernel->handle(object(Request)) in /home/tatsh/test-site/web/app_dev.php line 28