首页 文章

“assetic.filter_manager”服务是私有的[Symfony 3.4]

提问于
浏览
1

首先,我已经看到this question .

当我尝试将Symfony 3.3更新为3.4时,我得到了这个弃用:

User Deprecated: The "assetic.filter_manager" service is private, getting  it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

User Deprecated: The "assetic.filter.cssrewrite" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

The "security.acl" configuration key is deprecated since Symfony 3.4 and will be removed in 4.0. Install symfony/acl-bundle and use the "acl" key instead.
  • 我尝试在 src/MyBundle/Resources/services.yml 中添加:
services:
    Symfony\Bundle\AsseticBundle\AsseticBundle:
        public: true
  • 我安装了acl-bundle . 文件 config/security.yml
security:
    acl:
        connection: default

谢谢你的帮助

1 回答

  • 3

    正如您在评论中所知, assetic-bundle 已弃用,因此您无需更改其服务定义即可在Symfony 4上进行迁移 .

    但一般来说,如果要覆盖外部服务配置,可以实现自定义CompilerPass

    namespace AppBundle\DependencyInjection\Compiler;
    
    use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    
    class OverrideServiceCompilerPass implements CompilerPassInterface
    {
        public function process(ContainerBuilder $container)
        {
            $container->getDefinition('assetic.filter_manager')->setPublic(true);
            $container->getDefinition('assetic.filter.cssrewrite')->setPublic(true);
        }
    }
    

    并按照official documentation中的说明将其添加到您的包中 .

    namespace AppBundle;
    
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    use AppBundle\DependencyInjection\Compiler\OverrideServiceCompilerPass;
    
    class AppBundle extends Bundle
    {
        public function build(ContainerBuilder $container)
        {
            parent::build($container);
            $container->addCompilerPass(new OverrideServiceCompilerPass());
        }
    }
    

    请参阅Definition API文档 .

相关问题