10000 Routing cache broken when using generator_class · Issue #31807 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Routing cache broken when using generator_class #31807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pontus-mp opened this issue Jun 3, 2019 · 0 comments
Closed

Routing cache broken when using generator_class #31807

pontus-mp opened this issue Jun 3, 2019 · 0 comments

Comments

@pontus-mp
Copy link

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}
nicolas-grekas added a commit that referenced this issue Sep 6, 2019
…Fayet)

This PR was merged into the 4.3 branch.

Discussion
----------

[Router] routing cache crash when using generator_class

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31807
| License       | MIT

Since #28865 the Router use, by default, new generator, matcher, and dumpers.
This leads to crash when the Router use a custom generator, or matcher based on the old ones.

Commits
-------

a5b46e5 Fix routing cache broken when using generator_class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0