diff --git a/core/core.services.yml b/core/core.services.yml index 1aa5b84..20a950f 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -795,6 +795,18 @@ services: arguments: ['@router.route_provider', '@state', '@cache.bootstrap'] tags: - { name: 'event_subscriber' } + router.matcher.final_matcher: + class: Drupal\Core\Routing\UrlMatcher + arguments: ['@path.current'] + deprecated: true + router.matcher: + class: Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher + arguments: ['@router.route_provider'] + calls: + - [setFinalMatcher, ['@router.matcher.final_matcher']] + tags: + - { name: service_collector, tag: non_lazy_route_filter, call: addRouteFilter } + deprecated: true route_filter.lazy_collector: class: Drupal\Core\Routing\LazyRouteFilter tags: @@ -828,8 +840,14 @@ services: router: class: Drupal\Core\Routing\AccessAwareRouter arguments: ['@router.no_access_checks', '@access_manager', '@current_user'] + router.dynamic: + class: Symfony\Cmf\Component\Routing\DynamicRouter + arguments: ['@router.request_context', '@router.matcher', '@url_generator'] + tags: + - { name: service_collector, tag: non_lazy_route_enhancer, call: addRouteEnhancer } + deprecated: true router.no_access_checks: - class: \Drupal\Core\Routing\DynamicRouter + class: \Drupal\Core\Routing\Router arguments: ['@router.route_provider', '@path.current'] tags: - { name: service_collector, tag: non_lazy_route_enhancer, call: addRouteEnhancer } diff --git a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php index 1a729ab..14dc492 100644 --- a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php +++ b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php @@ -61,6 +61,7 @@ public function __call($name, $arguments) { if (method_exists($this->router, $name)) { return call_user_func_array([$this->router, $name], $arguments); } + throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", $name)); } /** @@ -120,14 +121,14 @@ protected function checkAccess(Request $request) { * {@inheritdoc} */ public function getRouteCollection() { - throw new \Exception('not supported'); + throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__)); } /** * {@inheritdoc} */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { - throw new \Exception('not supported'); + throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__)); } /** diff --git a/core/lib/Drupal/Core/Routing/Router.php b/core/lib/Drupal/Core/Routing/Router.php index 9344b83..f26bd99 100644 --- a/core/lib/Drupal/Core/Routing/Router.php +++ b/core/lib/Drupal/Core/Routing/Router.php @@ -13,7 +13,10 @@ use Symfony\Component\Routing\RouteCollection; /** - * Dynamic router handles the central piece of logic of routing in Drupal. + * Central router implementation in Drupal. + * + * A router determines, for an incoming process, the active controller, which is + * a callable that creates the output of the page. * * It consists of several steps, of which each are explained in more details * below: @@ -25,8 +28,14 @@ * regex: ::matchCollection() * - Enhance the list of route attributes, for example loading entity objects * : ::applyRouteEnhancers(). + * + * This implementation consists ideas of the following routers: + * + * @see \Symfony\Cmf\Component\Routing\DynamicRouter + * @see \Drupal\Core\Routing\UrlMatcher + * @see \Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher */ -class DynamicRouter extends UrlMatcher implements RequestMatcherInterface { +class Router extends UrlMatcher implements RequestMatcherInterface { /** * The route provider responsible for the first-pass match. @@ -62,21 +71,49 @@ class DynamicRouter extends UrlMatcher implements RequestMatcherInterface { protected $sortedFilters; /** + * Constructs a new Router. + * * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider + * The route provider. * @param \Drupal\Core\Path\CurrentPathStack $current_path + * The current path stuack. */ public function __construct(BaseRouteProviderInterface $route_provider, CurrentPathStack $current_path) { parent::__construct($current_path); $this->routeProvider = $route_provider; } - public function addRouteEnhancer(BaseRouteEnhancerInterface $routeEnhancer, $priority) { - $this->enhancers[$priority][] = $routeEnhancer; + /** + * Adds a route enhancer to the list of used route enhancers. + * + * @param \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface $route_enhancer + * A route enhancer. + * @param int $priority + * (optional) The priority of the enhancer. Higher number enhancers will be + * used first. + * + * @return $this + */ + public function addRouteEnhancer(BaseRouteEnhancerInterface $route_enhancer, $priority) { + $this->enhancers[$priority][] = $route_enhancer; return $this; } - public function addRouteFilter(BaseRouteFilterInterface $routeFilter, $priority) { - $this->filters[$priority][] = $routeFilter; + /** + * Adds a route filter to the list of used route filters. + * + * @param \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface $route_filter + * A route filter. + * @param int $priority + * (optional) The priority of the filter. Higher number filters will be used + * first. + * + * @return $this + */ + public function addRouteFilter(BaseRouteFilterInterface $route_filter, $priority = 0) { + $this->filters[$priority][] = $route_filter; + + return $this; } /** @@ -126,7 +163,9 @@ protected function getInitialRouteCollection(Request $request) { * The request. * * @return array - * The request attributes after applying the enhancers. + * The request attributes after applying the enhancers. This might consist + * raw values from the URL but also upcasted values, like entity objects, + * from route enhancers. */ protected function applyRouteEnhancers($defaults, Request $request) { foreach ($this->getRouteEnhancers() as $enhancer) {