symfony-cmf / routing-bundle

Symfony bundle to provide the CMF chain router to handle multiple routers, and the dynamic router to load routes from a database or other sources.
160 stars 78 forks source link

Route defaults validator breaks if twig is not installed #460

Closed alekitto closed 3 years ago

alekitto commented 3 years ago

I'm using this bundle to leverage dynamic routing capabilities on an API-based project. Twig is obviously not installed in production (in dev is a requirement of Symfony web-profiler.

When building the container image for production, the build breaks with this error:

The service "cmf_routing.validator.route_defaults" has a dependency on a non-existent service "twig.loader".

This is due to the RouteDefaultsTwigValidator class requiring a non-optional Twig\Loader\LoaderInterface as second argument. Unfortunately, this validator cannot be disabled by configuration, so I had to overwrite it with a custom version that not requires the twig loader.

One possible fix is to accept also null as $twig argument and skip the template check if the loader is not present.

Environment

PHP 8.0.3

symfony-cmf/routing        2.3.3
symfony-cmf/routing-bundle 2.4.2
dbu commented 3 years ago

thanks for the detailed report. i had a look, and this indeed does not make too much sense. the validator that is called "RouteDefaultsTwigValidator" also validates the route parameters with a router and thus is not only about twig.

glad if you can do a pull request to have the twig argument nullable and have the service definition for the validator say on-invalid="null". also, lets move twig to the dev-dependencies. no point in forcing you to have twig installed if we don't need it.

dbu commented 3 years ago

fixed in #461 and released as https://github.com/symfony-cmf/routing-bundle/releases/tag/2.5.0

thanks for bringing it up and adjusting it, @alekitto !