0
votes

I'm updating from Symfony 4 to Symfony 5.4. One of the changes to the Framework Bundle is RouteCollectionBuilder being deprecated in favour of RoutingConfigurator. But the problem is that I used to set default requirements for the routes like this:

$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
$routes->setRequirement('_locale', 'ru|en|ua|es|fr|pl|de|pt|it|be');

But new RoutingConfigurator does not have any method which replaces setRequirement. How can I define global/default requirements for all routes with the new configurator?

The other thing is that prefix argument is also disappeared, so I need to somehow use prefix for the whole route groups (I used to have 3 different route groups with different prefixes).

1

1 Answers

1
votes

Self-answering after some research.

So, new RoutingConfigurator::import() returns an instance of ImportConfigurator class, where you can set all default parameters.

So now my code looks like this:

$routes
    ->import($confDir . '/{routes}.yaml', 'glob')
    ->prefix('/');

$routes
    ->import($confDir . '/{routing}/*.yaml', 'glob')
    ->prefix('/{_locale}/')
    ->requirements(['_locale' => 'ru|en|ua|es|fr|pl|de|pt|it|be']);

$routes
    ->import($confDir . '/{routing}/' . $this->environment . '/*.yaml', 'glob')
    ->prefix('/');