diff --git a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php index 4c9b856..1a729ab 100644 --- a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php +++ b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php @@ -17,11 +17,11 @@ class AccessAwareRouter implements AccessAwareRouterInterface { /** - * The chain router doing the actual routing. + * The router doing the actual routing. * * @var \Symfony\Component\Routing\Matcher\RequestMatcherInterface */ - protected $chainRouter; + protected $router; /** * The access manager. @@ -40,15 +40,15 @@ class AccessAwareRouter implements AccessAwareRouterInterface { /** * Constructs a router for Drupal with access check and upcasting. * - * @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $chain_router - * The chain router doing the actual routing. + * @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $router + * The router doing the actual routing. * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The account to use in access checks. */ - public function __construct(RequestMatcherInterface $chain_router, AccessManagerInterface $access_manager, AccountInterface $account) { - $this->chainRouter = $chain_router; + public function __construct(RequestMatcherInterface $router, AccessManagerInterface $access_manager, AccountInterface $account) { + $this->router = $router; $this->accessManager = $access_manager; $this->account = $account; } @@ -57,17 +57,18 @@ public function __construct(RequestMatcherInterface $chain_router, AccessManager * {@inheritdoc} */ public function __call($name, $arguments) { - // Ensure to call every other function to the chained router. - // @todo Sadly does the ChainRouter not implement an interface in CMF. - return call_user_func_array([$this->chainRouter, $name], $arguments); + // Ensure to call every other function to the inner router. + if (method_exists($this->router, $name)) { + return call_user_func_array([$this->router, $name], $arguments); + } } /** * {@inheritdoc} */ public function setContext(SymfonyRequestContext $context) { - if ($this->chainRouter instanceof RequestContextAwareInterface) { - $this->chainRouter->setContext($context); + if ($this->router instanceof RequestContextAwareInterface) { + $this->router->setContext($context); } } @@ -75,8 +76,8 @@ public function setContext(SymfonyRequestContext $context) { * {@inheritdoc} */ public function getContext() { - if ($this->chainRouter instanceof RequestContextAwareInterface) { - return $this->chainRouter->getContext(); + if ($this->router instanceof RequestContextAwareInterface) { + return $this->router->getContext(); } } @@ -87,7 +88,7 @@ public function getContext() { * Thrown when access checking failed. */ public function matchRequest(Request $request) { - $parameters = $this->chainRouter->matchRequest($request); + $parameters = $this->router->matchRequest($request); $request->attributes->add($parameters); $this->checkAccess($request); // We can not return $parameters because the access check can change the diff --git a/core/lib/Drupal/Core/Routing/DynamicRouter.php b/core/lib/Drupal/Core/Routing/DynamicRouter.php index 0a1288a..e38b40a 100644 --- a/core/lib/Drupal/Core/Routing/DynamicRouter.php +++ b/core/lib/Drupal/Core/Routing/DynamicRouter.php @@ -17,7 +17,14 @@ * * It consists of several steps, of which each are explained in more details * below: - * - Get a collection of routes which potentially match the current request. + * - Get a collection of routes which potentially match the current request: + * This is done by the route provider ::getInitialRouteCollection() + * - Filter the collection down further more. For example this filters out + * routes applying to other formats: ::applyRouteFilters() + * - Find the best matching route out of the remaining one, by applying a + * regex: ::matchCollection() + * - Enhance the list of route attributes, for example loading entity objects + * : ::applyRouteEnhancers(). */ class DynamicRouter extends UrlMatcher implements RequestMatcherInterface { @@ -85,11 +92,10 @@ public function match($pathinfo) { * {@inheritdoc} */ public function matchRequest(Request $request) { - $collection = $this->routeProvider->getRouteCollectionForRequest($request); - + $collection = $this->getInitialRouteCollection($request); $collection = $this->applyRouteFilters($collection, $request); - if ($ret = $this->matchCollection(rawurldecode($this->currentPath->getPath()), $collection)) { + if ($ret = $this->matchCollection(rawurldecode($this->currentPath->getPath($request)), $collection)) { return $this->applyRouteEnhancers($ret, $request); } @@ -99,6 +105,19 @@ public function matchRequest(Request $request) { } /** + * Returns a collection of potential matching routes for a request. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. + * + * @return \Symfony\Component\Routing\RouteCollection + * The initial fetched route collection. + */ + protected function getInitialRouteCollection(Request $request) { + return $this->routeProvider->getRouteCollectionForRequest($request); + } + + /** * Apply the route enhancers to the defaults, according to priorities * * @param array $defaults