我在研究如何覆盖symfony的一个组件。在我的具体情况下,我希望覆盖翻译组件的MessageCatalogue类,以便能够在没有找到翻译时发送事件。这有可能吗?
发布于 2016-01-04 09:31:45
是的,是这样的。这是关于如何覆盖包的任何部分的详细指南。第一个例子显示了您要寻找的内容。
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
namespace Acme\DemoBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class OverrideServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('original-service-id');
$definition->setClass('Acme\DemoBundle\YourService');
}
}然而,xabbuh对您的问题的评论似乎是一个更容易的解决方案。
https://stackoverflow.com/questions/34587613
复制相似问题