diff --git a/core/lib/Drupal/Core/Routing/CompiledRoute.php b/core/lib/Drupal/Core/Routing/CompiledRoute.php index 7354e12..5fb1b4a 100644 --- a/core/lib/Drupal/Core/Routing/CompiledRoute.php +++ b/core/lib/Drupal/Core/Routing/CompiledRoute.php @@ -177,7 +177,19 @@ public function getRequirements() { * {@inheritdoc} */ public function serialize() { - $data = unserialize(parent::serialize()); + $data = []; + // All symfony provided variables. + // @todo A lot of them are actually not used by Drupal, at least for now, + // so think about optimize them out. + $data['vars'] = $this->getVariables(); + $data['path_prefix'] = $this->getStaticPrefix(); + $data['path_regex'] = $this->getRegex(); + $data['path_tokens'] = $this->getTokens(); + $data['path_vars'] = $this->getPathVariables(); + $data['host_regex'] = $this->getHostRegex(); + $data['host_tokens'] = $this->getHostTokens(); + $data['host_vars'] = $this->getHostVariables(); + $data['fit'] = $this->fit; $data['patternOutline'] = $this->patternOutline; $data['numParts'] = $this->numParts; @@ -188,9 +200,9 @@ public function serialize() { /** * {@inheritdoc} */ - public function unserialize($serialized) - { + public function unserialize($serialized) { parent::unserialize($serialized); + $data = unserialize($serialized); $this->fit = $data['fit']; diff --git a/core/lib/Drupal/Core/Routing/RoutePreloader.php b/core/lib/Drupal/Core/Routing/RoutePreloader.php index 7952d17..c45bee6 100644 --- a/core/lib/Drupal/Core/Routing/RoutePreloader.php +++ b/core/lib/Drupal/Core/Routing/RoutePreloader.php @@ -85,7 +85,7 @@ public function onRequest(KernelEvent $event) { */ protected function loadNonAdminRoutes() { if ($routes = $this->state->get('routing.non_admin_routes', array())) { - $this->routeProvider->getRoutesByNames($routes); + $this->routeProvider->getRoutesByNames($routes, FALSE); } } diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index da9dc1b..58597c1 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -153,22 +153,9 @@ public function getRouteByName($name) { } /** - * Find many routes by their names using the provided list of names. - * - * Note that this method may not throw an exception if some of the routes - * are not found. It will just return the list of those routes it found. - * - * This method exists in order to allow performance optimizations. The - * simple implementation could be to just repeatedly call - * $this->getRouteByName(). - * - * @param array $names - * The list of names to retrieve. - * - * @return \Symfony\Component\Routing\Route[] - * Iterable thing with the keys the names of the $names argument. + * {@inheritdoc} */ - public function getRoutesByNames($names) { + public function getRoutesByNames($names, $unserialize = TRUE) { if (empty($names)) { throw new \InvalidArgumentException('You must specify the route names to load'); @@ -181,11 +168,17 @@ public function getRoutesByNames($names) { $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(); - foreach ($routes as $name => $route) { - $this->routes[$name] = unserialize($route); - } + $this->routes += $routes; } + if ($unserialize) { + foreach ($names as $name) { + // The specified route name might not exist. + if (isset($this->routes[$name])) { + $this->routes[$name] = is_string($this->routes[$name]) ? unserialize($this->routes[$name]) : $this->routes[$name]; + } + } + } return array_intersect_key($this->routes, array_flip($names)); } diff --git a/core/lib/Drupal/Core/Routing/RouteProviderInterface.php b/core/lib/Drupal/Core/Routing/RouteProviderInterface.php index 8c8e356..d4450b5 100644 --- a/core/lib/Drupal/Core/Routing/RouteProviderInterface.php +++ b/core/lib/Drupal/Core/Routing/RouteProviderInterface.php @@ -18,6 +18,27 @@ interface RouteProviderInterface extends RouteProviderBaseInterface { /** + * Find many routes by their names using the provided list of names. + * + * Note that this method may not throw an exception if some of the routes + * are not found. It will just return the list of those routes it found. + * + * This method exists in order to allow performance optimizations. The + * simple implementation could be to just repeatedly call + * $this->getRouteByName(). + * + * @param array $names + * The list of names to retrieve. + * + * @param bool $unserialize + * (optional) Determines whether the routes should be unserialized. + * + * @return string[]\Symfony\Component\Routing\Route[] + * Iterable thing with the keys the names of the $names argument. + */ + public function getRoutesByNames($names, $unserialize = TRUE); + + /** * Get all routes which match a certain pattern. * * @param string $pattern diff --git a/core/modules/system/src/Tests/Routing/MockRouteProvider.php b/core/modules/system/src/Tests/Routing/MockRouteProvider.php index dce1b27..0bd8b66 100644 --- a/core/modules/system/src/Tests/Routing/MockRouteProvider.php +++ b/core/modules/system/src/Tests/Routing/MockRouteProvider.php @@ -59,7 +59,7 @@ public function getRouteByName($name) { /** * Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRoutesByName(). */ - public function getRoutesByNames($names) { + public function getRoutesByNames($names, $unserialize = TRUE) { $routes = array(); foreach ($names as $name) { $routes[] = $this->routes->get($name); diff --git a/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php b/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php index 109a3f2..9077ee7 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php @@ -168,7 +168,7 @@ public function testOnRequestOnHtml() { $this->routeProvider->expects($this->once()) ->method('getRoutesByNames') - ->with(array('test2')); + ->with(['test2'], FALSE); $this->state->expects($this->once()) ->method('get') ->with('routing.non_admin_routes')