Symfony 4.3: User Deprecated: The Symfony\Bundle\TwigBundle\Loader\FilesystemLoader class is deprecated since version 4.3 and will be removed in 5.0 …

后端 未结 1 410
一个人的身影
一个人的身影 2021-02-08 15:32

After upgrading to Symfony 4.3, I\'m getting the following 22 deprecation warnings:

User Deprecated: The Symfony\\Bundle\\TwigBundle\\Loader\\FilesystemLoade

1条回答
  •  盖世英雄少女心
    2021-02-08 15:45

    This is due to the deprecation of the templating component, see https://symfony.com/blog/new-in-symfony-4-3-deprecated-the-templating-component-integration

    Solution:

    1. Remove "symfony/templating" from composer.json
    2. Remove this from framework.yaml:
      templating:
          engines:
              - twig
      
    3. Run composer update

    This should remove all the deprecation warnings.

    If you're getting this error

    Cannot autowire service "...": argument "$templating" of method "__construct()" references interface "Symfony\Bundle\FrameworkBundle\Templating\EngineInterface" but no such service exists. Did you create a class that implements this interface?

    ... you're still using the old templating in some service.
    Solution: Change the dependency from Symfony\Bundle\FrameworkBundle\Templating\EngineInterface to Twig\Environment:

    use Twig\Environment;
    
    private $twig;
    
    public function __construct(Environment $twig)
    {
        $this->twig = $twig;
    }
    

    See also https://github.com/symfony/symfony/issues/31645

    0 讨论(0)
提交回复
热议问题