如何删除 Symfony2 中的服务定义? [英] How to remove a service definition in Symfony2?

查看:17
本文介绍了如何删除 Symfony2 中的服务定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个定义是在 Symfony v2.7 中添加的 https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml#L156

This definition was added in v2.7 of Symfony https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml#L156

这是因为在 2.7 中添加了 TranslationsCacheWarmer:https://github.com/Bsymundle/Frame/commit/4d4a85bed21604132db86d24d0af101518a18d50

This was because TranslationsCacheWarmer was added in 2.7: https://github.com/symfony/FrameworkBundle/commit/4d4a85bed21604132db86d24d0af101518a18d50

不幸的是,这破坏了我的一些代码,这在我尝试清除 Symfony 缓存时很明显.我使用 PHP 来处理翻译,这些文件中有一些自定义代码(即依赖相对路径的 DirectoryIterator...),现在正在中断.

Unfortunately this has broken some of my code, which is evident when I try to clear the Symfony cache. I use PHP to handle translations, and there is some custom code in these files (namely a DirectoryIterator which is relying on a relative path...) which is now breaking.

我的计划是为此提出适当的解决方法.但是,作为短期修复 - 是否可以删除我在此消息的第一行中引用的定义?我的理解是,当我运行 php app/console cache:clear --env=prod

My plan is to come up with a proper workaround for this. However, as a short term fix - is it possible to remove that definition I reference on the first line of this message? My understanding is that this will stop the TranslationsCacheWarmer from doing anything when I run php app/console cache:clear --env=prod

我知道我可能只是从 translation.xml 中删除该块 - 但是,它深深嵌入 vendor/ 目录中,这显然不是我的 git 存储库的一部分.理想情况下,我希望能够仅通过编辑我自己的代码来解决这个问题,这样更改就会传递给其他人.我希望也许有什么方法可以让我覆盖它,也许是通过编译器通行证之类的?

I know I could probably just delete that block from translation.xml - however, that is embedded deep in the vendor/ directory which is obviously not part of my git repository. Ideally, I'd like to be able to solve this by editing my own code only, so that the change will flow through to others. I was hoping maybe there is some way for me to override this, maybe with a compiler pass or something?

大家有什么建议吗?

推荐答案

要取消注册其他 bundles 注册的服务,可以使用 编译器通过.

To unregister services registered by other bundles, you can use compiler pass.

它看起来像:

<?php

namespace Acme\Bundle\AppBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class UnregisterThirdPartyServicesPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $container->removeDefinition('translation.warmer');
    }
}

这篇关于如何删除 Symfony2 中的服务定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆