class UrlMatcher

Same name in other branches
  1. 9 core/lib/Drupal/Core/Routing/UrlMatcher.php \Drupal\Core\Routing\UrlMatcher
  2. 8.9.x core/lib/Drupal/Core/Routing/UrlMatcher.php \Drupal\Core\Routing\UrlMatcher
  3. 10 core/lib/Drupal/Core/Routing/UrlMatcher.php \Drupal\Core\Routing\UrlMatcher

Drupal-specific URL Matcher; handles the Drupal "system path" mapping.

Hierarchy

  • class \Drupal\Core\Routing\UrlMatcher extends \Symfony\Component\Routing\Matcher\UrlMatcher

Expanded class hierarchy of UrlMatcher

File

core/lib/Drupal/Core/Routing/UrlMatcher.php, line 14

Namespace

Drupal\Core\Routing
View source
class UrlMatcher extends BaseUrlMatcher {
    
    /**
     * The current path.
     *
     * @var \Drupal\Core\Path\CurrentPathStack
     */
    protected $currentPath;
    
    /**
     * Constructs a new UrlMatcher.
     *
     * The parent class has a constructor we need to skip, so just override it
     * with a no-op.
     *
     * @param \Drupal\Core\Path\CurrentPathStack $current_path
     *   The current path.
     */
    public function __construct(CurrentPathStack $current_path) {
        $this->currentPath = $current_path;
    }
    public function finalMatch(RouteCollection $collection, Request $request) {
        $this->routes = $collection;
        $context = new RequestContext();
        $context->fromRequest($request);
        $this->setContext($context);
        return $this->match($this->currentPath
            ->getPath($request));
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getAttributes(Route $route, $name, array $attributes) : array {
        if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
            $name = $route->getRouteKey();
        }
        $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
        $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;
        return $this->mergeDefaults($attributes, $route->getDefaults());
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
UrlMatcher::$currentPath protected property The current path.
UrlMatcher::finalMatch public function
UrlMatcher::getAttributes protected function
UrlMatcher::__construct public function Constructs a new UrlMatcher. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.