From a5b46e53900c0360f52f53d96a0223c7540f798a Mon Sep 17 00:00:00 2001 From: dFayet Date: Sun, 9 Jun 2019 18:42:38 +0200 Subject: [PATCH] Fix routing cache broken when using generator_class --- src/Symfony/Component/Routing/Router.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 457316f8a0..5f8d9ffb15 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -23,11 +23,13 @@ use Symfony\Component\Routing\Generator\CompiledUrlGenerator; use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface; use Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper; use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface; +use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Matcher\CompiledUrlMatcher; use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper; use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface; +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Matcher\UrlMatcherInterface; @@ -394,6 +396,11 @@ class Router implements RouterInterface, RequestMatcherInterface */ protected function getGeneratorDumperInstance() { + // For BC, fallback to PhpGeneratorDumper if the UrlGenerator and UrlGeneratorDumper are not consistent with each other + if (is_a($this->options['generator_class'], CompiledUrlGenerator::class, true) !== is_a($this->options['generator_dumper_class'], CompiledUrlGeneratorDumper::class, true)) { + return new PhpGeneratorDumper($this->getRouteCollection()); + } + return new $this->options['generator_dumper_class']($this->getRouteCollection()); } @@ -402,6 +409,11 @@ class Router implements RouterInterface, RequestMatcherInterface */ protected function getMatcherDumperInstance() { + // For BC, fallback to PhpMatcherDumper if the UrlMatcher and UrlMatcherDumper are not consistent with each other + if (is_a($this->options['matcher_class'], CompiledUrlMatcher::class, true) !== is_a($this->options['matcher_dumper_class'], CompiledUrlMatcherDumper::class, true)) { + return new PhpMatcherDumper($this->getRouteCollection()); + } + return new $this->options['matcher_dumper_class']($this->getRouteCollection()); }