Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 5.1 Deprecation RouteCollectionBuilder -> RoutingConfigurator

I am updating a Symfony project from 5.0 to 5.1 There is this one deprecation hint saying RouteCollectionBuilder is deprecated and RoutingConfigurator should be used instead.

The exact message is

Since symfony/routing 5.1: The "Symfony\Component\Routing\RouteCollectionBuilder" class is deprecated, use "Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator" instead.

How is this supposed to be implemented? Am I supposed to change code in the vendors folder?

like image 235
user3440145 Avatar asked Jun 04 '20 15:06

user3440145


Video Answer


2 Answers

If anyone has problems fixing this depreciation

Since symfony/routing 5.1: The "Symfony\Component\Routing\RouteCollectionBuilder" class is deprecated, use "Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator" instead.

Here is my updated file src/Kernel.php

<?php

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    protected function configureContainer(ContainerConfigurator $container): void
    {
        $container->import('../config/{packages}/*.yaml');
        $container->import('../config/{packages}/'.$this->environment.'/*.yaml');

        if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
            $container->import('../config/services.yaml');
            $container->import('../config/{services}_'.$this->environment.'.yaml');
        } elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
            (require $path)($container->withPath($path), $this);
        }
    }

    protected function configureRoutes(RoutingConfigurator $routes): void
    {
        $routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
        $routes->import('../config/{routes}/*.yaml');

        if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
            $routes->import('../config/routes.yaml');
        } elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) {
            (require $path)($routes->withPath($path), $this);
        }
    }
}
like image 112
arno Avatar answered Oct 11 '22 14:10

arno


You need to update Kernel class to start using RoutingConfigurator instead of RouteCollectionBuilder.

You can do it automatically by updating the recipe (composer recipes:install symfony/framework-bundle --force).

like image 22
Leprechaun Avatar answered Oct 11 '22 14:10

Leprechaun