diff --git a/core/lib/Drupal/Core/Routing/AdminContext.php b/core/lib/Drupal/Core/Routing/AdminContext.php index dac5839..ed3305b 100644 --- a/core/lib/Drupal/Core/Routing/AdminContext.php +++ b/core/lib/Drupal/Core/Routing/AdminContext.php @@ -9,7 +9,6 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Routing\Route; /** * Provides a helper class to determine whether the route is an admin one. diff --git a/core/lib/Drupal/Core/Routing/CompiledRoute.php b/core/lib/Drupal/Core/Routing/CompiledRoute.php index 45aa22c..70a49a1 100644 --- a/core/lib/Drupal/Core/Routing/CompiledRoute.php +++ b/core/lib/Drupal/Core/Routing/CompiledRoute.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Routing; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\CompiledRoute as SymfonyCompiledRoute; /** diff --git a/core/lib/Drupal/Core/Routing/MatcherDumper.php b/core/lib/Drupal/Core/Routing/MatcherDumper.php index 18e864f..f651323 100644 --- a/core/lib/Drupal/Core/Routing/MatcherDumper.php +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php @@ -109,6 +109,7 @@ public function dump(array $options = array()) { 'pattern_outline', 'number_parts', 'route', + 'compiled_route', )); $names = array(); foreach ($routes as $name => $route) { @@ -128,6 +129,7 @@ public function dump(array $options = array()) { 'pattern_outline' => $compiled->getPatternOutline(), 'number_parts' => $compiled->getNumParts(), 'route' => serialize($route), + 'compiled_route' => serialize($compiled), ); $insert->values($values); } diff --git a/core/lib/Drupal/Core/Routing/NullGenerator.php b/core/lib/Drupal/Core/Routing/NullGenerator.php index 6ec6e11..8154e14 100644 --- a/core/lib/Drupal/Core/Routing/NullGenerator.php +++ b/core/lib/Drupal/Core/Routing/NullGenerator.php @@ -10,7 +10,6 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\RequestContext as SymfonyRequestContext; use Symfony\Component\Routing\Exception\RouteNotFoundException; -use Symfony\Component\Routing\Route; /** * No-op implementation of a Url Generator, needed for backward compatibility. diff --git a/core/lib/Drupal/Core/Routing/Route.php b/core/lib/Drupal/Core/Routing/Route.php new file mode 100644 index 0000000..3fdd281 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/Route.php @@ -0,0 +1,45 @@ +compiled)) { + return $this->compiled; + } + return parent::compile(); + } + + /** + * Sets the compiled route. + * + * @param \Drupal\Core\Routing\CompiledRoute $compiled + * The compiled route. + * + * @return $this + */ + public function setCompiled(CompiledRoute $compiled) { + $this->compiled = $compiled; + return $this; + } + +} diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php index e201b42..1bbd393 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -13,7 +13,6 @@ use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Routing\RouteCollection; -use Symfony\Component\Routing\Route; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Lock\LockBackendInterface; diff --git a/core/lib/Drupal/Core/Routing/RouteCompiler.php b/core/lib/Drupal/Core/Routing/RouteCompiler.php index 6ae58e1..0f72b7c 100644 --- a/core/lib/Drupal/Core/Routing/RouteCompiler.php +++ b/core/lib/Drupal/Core/Routing/RouteCompiler.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Routing; use Symfony\Component\Routing\RouteCompilerInterface; -use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\Route as BaseRoute; use Symfony\Component\Routing\RouteCompiler as SymfonyRouteCompiler; /** @@ -35,7 +35,7 @@ class RouteCompiler extends SymfonyRouteCompiler implements RouteCompilerInterfa * @return \Drupal\Core\Routing\CompiledRoute * A CompiledRoute instance. */ - public static function compile(Route $route) { + public static function compile(BaseRoute $route) { $symfony_compiled = parent::compile($route); diff --git a/core/lib/Drupal/Core/Routing/RouteMatch.php b/core/lib/Drupal/Core/Routing/RouteMatch.php index eafb184..30e1f85 100644 --- a/core/lib/Drupal/Core/Routing/RouteMatch.php +++ b/core/lib/Drupal/Core/Routing/RouteMatch.php @@ -10,7 +10,6 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Route; /** * Default object representing the results of routing. diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index cc0682a..84e7a0d 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -176,11 +176,12 @@ public function getRoutesByNames($names) { $routes_to_load = array_diff($names, array_keys($this->routes)); if ($routes_to_load) { - $result = $this->connection->query('SELECT name, route FROM {' . $this->connection->escapeTable($this->tableName) . '} WHERE name IN (:names)', array(':names' => $routes_to_load)); - $routes = $result->fetchAllKeyed(); + $result = $this->connection->query('SELECT name, route, compiled_route FROM {' . $this->connection->escapeTable($this->tableName) . '} WHERE name IN (:names)', array(':names' => $routes_to_load)) + ->fetchAllAssoc('name'); - foreach ($routes as $name => $route) { - $this->routes[$name] = unserialize($route); + foreach ($result as $name => $data) { + $this->routes[$name] = unserialize($data->route); + $this->routes[$name]->setCompiled(unserialize($data->compiled_route)); } } @@ -287,14 +288,18 @@ protected function getRoutesByPath($path) { return $collection; } - $routes = $this->connection->query("SELECT name, route FROM {" . $this->connection->escapeTable($this->tableName) . "} WHERE pattern_outline IN (:patterns) ORDER BY fit DESC, name ASC", array( + $routes = $this->connection->query("SELECT name, route, compiled_route FROM {" . $this->connection->escapeTable($this->tableName) . "} WHERE pattern_outline IN (:patterns) ORDER BY fit DESC, name ASC", array( ':patterns' => $ancestors, )) - ->fetchAllKeyed(); + ->fetchAllAssoc('name'); - foreach ($routes as $name => $route) { + foreach ($routes as $name => $data) { + $route = $data->route; $route = unserialize($route); - if (preg_match($route->compile()->getRegex(), $path, $matches)) { + /** @var \Drupal\Core\Routing\CompiledRoute $compiled */ + $compiled = unserialize($data->compiled_route); + $route->setCompiled($compiled); + if (preg_match($compiled->getRegex(), $path, $matches)) { $collection->add($name, $route); } } diff --git a/core/modules/config_translation/src/ConfigEntityMapper.php b/core/modules/config_translation/src/ConfigEntityMapper.php index 2cbc78e..6d4dc5f 100644 --- a/core/modules/config_translation/src/ConfigEntityMapper.php +++ b/core/modules/config_translation/src/ConfigEntityMapper.php @@ -11,13 +11,13 @@ use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Routing\Route; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; use Drupal\locale\LocaleConfigManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Route; /** * Configuration mapper for configuration entities. diff --git a/core/modules/config_translation/src/ConfigNamesMapper.php b/core/modules/config_translation/src/ConfigNamesMapper.php index ed796af..4aa8897 100644 --- a/core/modules/config_translation/src/ConfigNamesMapper.php +++ b/core/modules/config_translation/src/ConfigNamesMapper.php @@ -12,6 +12,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Plugin\PluginBase; +use Drupal\Core\Routing\Route; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -19,7 +20,6 @@ use Drupal\locale\LocaleConfigManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; /** diff --git a/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php index ce8bd57..4e1a64f 100644 --- a/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php +++ b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php @@ -9,9 +9,9 @@ use Drupal\content_translation\ContentTranslationManagerInterface; use Drupal\Core\Access\AccessManagerInterface; +use Drupal\Core\Routing\Route; use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; /** diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 3abb6cf..d08667c 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -8,9 +8,9 @@ namespace Drupal\field_ui\Routing; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Routing\Route; use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; /** diff --git a/core/modules/image/src/Routing/ImageStyleRoutes.php b/core/modules/image/src/Routing/ImageStyleRoutes.php index 39b2379..7790358 100644 --- a/core/modules/image/src/Routing/ImageStyleRoutes.php +++ b/core/modules/image/src/Routing/ImageStyleRoutes.php @@ -7,7 +7,7 @@ namespace Drupal\image\Routing; -use Symfony\Component\Routing\Route; +use Drupal\Core\Routing\Route; /** * Defines a route subscriber to register a url for serving image styles. diff --git a/core/modules/search/src/Routing/SearchPageRoutes.php b/core/modules/search/src/Routing/SearchPageRoutes.php index 0d30957..696b1d6 100644 --- a/core/modules/search/src/Routing/SearchPageRoutes.php +++ b/core/modules/search/src/Routing/SearchPageRoutes.php @@ -8,9 +8,9 @@ namespace Drupal\search\Routing; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Routing\Route; use Drupal\search\SearchPageRepositoryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Routing\Route; /** * Provides dynamic routes for search. diff --git a/core/modules/system/system.install b/core/modules/system/system.install index c1751c4..4368c99 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -818,6 +818,11 @@ function system_schema() { 'type' => 'blob', 'size' => 'big', ), + 'compiled_route' => array( + 'description' => 'A serialized CompiledRoute object', + 'type' => 'blob', + 'size' => 'big', + ), 'number_parts' => array( 'description' => 'Number of parts in this router path.', 'type' => 'int', diff --git a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php index 5902b09..51dd2d7 100644 --- a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php +++ b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php @@ -7,7 +7,7 @@ namespace Drupal\entity_test\Routing; -use Symfony\Component\Routing\Route; +use Drupal\Core\Routing\Route; /** * Subscriber for Entity Test routes. diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 754408c..d039d7b 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Routing\Route; use Drupal\Core\Routing\UrlGeneratorTrait; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteCompiler; @@ -20,7 +21,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; /** diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php index e28261b..9393236 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php @@ -9,11 +9,11 @@ use Drupal\Component\Discovery\YamlDiscovery; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Routing\Route; use Drupal\Core\Routing\RouteBuilder; use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RoutingEvents; use Drupal\Tests\UnitTestCase; -use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; /**