Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Router.php

function Router::getMatcher

Gets the UrlMatcher or RequestMatcher instance associated with this Router.

1 call to Router::getMatcher()
Router::matchRequest in vendor/symfony/routing/Router.php
Tries to match a request with a set of routes.

File

vendor/symfony/routing/Router.php, line 194

Class

Router
The Router class is an example of the integration of all pieces of the routing system for easier use.

Namespace

Symfony\Component\Routing

Code

public function getMatcher() : UrlMatcherInterface|RequestMatcherInterface {
    if (isset($this->matcher)) {
        return $this->matcher;
    }
    if (null === $this->options['cache_dir']) {
        $routes = $this->getRouteCollection();
        $compiled = is_a($this->options['matcher_class'], CompiledUrlMatcher::class, true);
        if ($compiled) {
            $routes = (new CompiledUrlMatcherDumper($routes))->getCompiledRoutes();
        }
        $this->matcher = new $this->options['matcher_class']($routes, $this->context);
        if (method_exists($this->matcher, 'addExpressionLanguageProvider')) {
            foreach ($this->expressionLanguageProviders as $provider) {
                $this->matcher
                    ->addExpressionLanguageProvider($provider);
            }
        }
        return $this->matcher;
    }
    $cache = $this->getConfigCacheFactory()
        ->cache($this->options['cache_dir'] . '/url_matching_routes.php', function (ConfigCacheInterface $cache) {
        $dumper = $this->getMatcherDumperInstance();
        if (method_exists($dumper, 'addExpressionLanguageProvider')) {
            foreach ($this->expressionLanguageProviders as $provider) {
                $dumper->addExpressionLanguageProvider($provider);
            }
        }
        $cache->write($dumper->dump(), $this->getRouteCollection()
            ->getResources());
        unset(self::$cache[$cache->getPath()]);
    });
    return $this->matcher = new $this->options['matcher_class'](self::getCompiledRoutes($cache->getPath()), $this->context);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal