Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 …

Tags:

php

twig

symfony

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

User Deprecated: The Symfony\Bundle\TwigBundle\Loader\FilesystemLoader class is deprecated since version 4.3 and will be removed in 5.0; use Twig notation for templates instead.

User Deprecated: The "templating.locator" service is deprecated since Symfony 4.3 and will be removed in 5.0.

User Deprecated: The Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

User Deprecated: The "templating.name_parser" service is deprecated since Symfony 4.3 and will be removed in 5.0.

User Deprecated: The Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

User Deprecated: Using the "templating" service is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

User Deprecated: The Symfony\Bridge\Twig\TwigEngine class is deprecated since version 4.3 and will be removed in 5.0; use \Twig\Environment instead.

User Deprecated: The Symfony\Bundle\FrameworkBundle\Templating\EngineInterface interface is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

User Deprecated: The Symfony\Bundle\TwigBundle\TwigEngine class is deprecated since version 4.3 and will be removed in 5.0; use \Twig\Environment instead.

2 times: The "framework.templating" configuration is deprecated since Symfony 4.3. Configure the "twig" section provided by the Twig Bundle instead.

Enabling the Templating component is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

The "templating.cache_warmer.template_paths" service is deprecated since Symfony 4.3 and will be removed in 5.0.

The Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

The "templating.finder" service is deprecated since Symfony 4.3 and will be removed in 5.0.

The Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

The Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface interface is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

The "templating.locator" service is deprecated since Symfony 4.3 and will be removed in 5.0.

The Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

The Symfony\Bundle\FrameworkBundle\Templating\TemplateReference class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

The "templating.name_parser" service is deprecated since Symfony 4.3 and will be removed in 5.0.

The Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.

like image 584
Thomas Landauer Avatar asked Oct 14 '19 16:10

Thomas Landauer


1 Answers

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

like image 131
Thomas Landauer Avatar answered Nov 09 '22 23:11

Thomas Landauer