我想从Symfony取消注册服务cmf_block.reference_admin . 经过一些研究后我发现,它应该通过CompilerPass来完成 . 以下是我删除它的方法:
namespace PortalBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class UnregisterThirdPartyServicesPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if($container->getDefinition('cmf_block.reference_admin'))
$container->removeDefinition('cmf_block.reference_admin');
}
}
完成后,我收到一个错误:
未捕获的异常'Symfony \ Component \ DependencyInjection \ Exception \ ServiceNotFoundException',并显示消息'您已请求不存在的服务“cmf_block.reference_admin” . '在xxx \ cmf-sandbox-master \ app \ bootstrap.php.cache:2198堆栈跟踪:#0 xxx \ cmf-sandbox-master \ app \ cache \ dev \ classes.php(11818):Symfony \ Component \ DependencyInjection \ Container-> get('cmf_block.refer ...')#1 xxx \ cmf-sandbox-master \ vendor \ sonata-project \ admin-bundle \ Route \ RoutesCacheWarmUp.php(47):Sonata \ AdminBundle \ Admin \ Pool - > getInstance('cmf_block.refer ...')#2 xxx \ cmf-sandbox-master \ vendor \ symfony \ symfony \ src \ Symfony \ Component \ HttpKernel \ CacheWarmer \ CacheWarmerAggregate.php(48):Sonata \ AdminBundle \ Route \ RoutesCacheWarmUp-> warmUp('xxx')#3 xxx \ cmf-sandbox-master \ app \ bootstrap.php.cache(2711):Symfony \ Component \ HttpKernel \ CacheWarmer \ CacheWarmerAggregate-> warmUp('C:\ in第2198行的xxx \ cmf-sandbox-master \ app \ bootstrap.php.cache
也许你们中的某些人可以帮助我或知道,如何从我的Symfony中删除CMF Block Bundle的Reference Block功能 .
非常感谢提前!
2 回答
Check if the service exist before try to remove it,例如:
并在服务真正存在于容器中的那一刻添加您的编译器传递 . 检查here如何控制通行证订购 . 例如,注册如下:
希望这有帮助
好的,我似乎无法取消注册此特定服务 . 我认为它在第三方捆绑中太深了 .
我的(非常简单,不是真的让我开心)现在解决方法:禁止向每个用户提供服务的所有路由,因此无法访问它并从仪表板中删除链接 .
感谢您的帮助 - 如果有人知道如何完成上述工作 - 我将永远感兴趣!