Closed
Description
Symfony version(s) affected: 4.3.0
Description
Setting both cache_dir and generator_class in the Router class is broken in symfony/routing 4.3.0. This worked fine in 4.2.8.
Note, only the symfony/routing component is used and not the entire symfony framework.
How to reproduce
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Loader\ClosureLoader;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router;
require_once '../vendor/autoload.php';
class OurUrlGenerator extends UrlGenerator {}
$routeClosure = function () {
$route = new Route('/foo', ['_controller' => 'MyController']);
$routes = new RouteCollection();
$routes->add('route_name', $route);
return $routes;
};
$context = new RequestContext('/');
$cacheDir = realpath(dirname(__FILE__) . '/../') . '/var/cache/routes';
$routerOptions = [
'generator_class' => OurUrlGenerator::class,
'cache_dir' => $cacheDir,
];
$context = new RequestContext();
$baseRouter = new Router(new ClosureLoader(), $routeClosure, $routerOptions, $context);
// Crash here, "Class 'UrlGenerator' not found"
echo $baseRouter->generate('route_name');
Additional context
Error: Class 'UrlGenerator' not found in /mostphotos/vendor/symfony/routing/Router.php:375
Stack trace:
#0 /mostphotos/vendor/symfony/routing/Router.php(254): Symfony\Component\Routing\Router->getGenerator()
#1 /mostphotos/public/index.php(34): Symfony\Component\Routing\Router->generate('route_name')
#2 {main}