我在我的symfony项目中有捆绑包,我想在此捆绑包中更改doctrine.orm.listeners.resolve_target_entity
服务。我在编译器传递
symfony / symfony v3.2.3
doctrine / common v2.7.2
doctrine / dbal v2.5.12
doctrine / orm v2.5.6
doctrine / doctrine-bundle 1.6.7
namespace XXX\MyBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use XXX\MyBundle\DependencyInjection\Compiler\PreparePass;
class XXXMyBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new PreparePass());
}
}
namespace XXX\MyBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class PreparePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->findDefinition('doctrine.orm.listeners.resolve_target_entity');
$definition->addMethodCall('addResolveTargetEntity', array(
'class1', 'class2', array(),
));
$definition->addTag('doctrine.event_subscriber', array());
}
}
添加方法调用,添加标记,./bin/console debug:container
显示一切正常。但是事实上,服务没有添加到学说订阅者,getDoctrine_Dbal_DefaultConnectionService
函数中的容器转储中没有代码。
如果我在DoctrineBundle之前注册我的包,它可以工作,如果它不起作用:)我找不到处理doctrine.event_subscriber
标签的位置。
无论捆绑注册顺序如何,是否可以使其工作?处理doctrine.event_subscriber
标记的位置?
任何帮助,谢谢