You are here

public function Router::matchRequest in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Routing/Router.php \Drupal\Core\Routing\Router::matchRequest()
1 call to Router::matchRequest()
Router::match in core/lib/Drupal/Core/Routing/Router.php

File

core/lib/Drupal/Core/Routing/Router.php, line 109

Class

Router
Router implementation in Drupal.

Namespace

Drupal\Core\Routing

Code

public function matchRequest(Request $request) {
  try {
    $collection = $this
      ->getInitialRouteCollection($request);
  } catch (\TypeError $e) {
    \Drupal::service('router.builder')
      ->rebuild();
    $collection = $this
      ->getInitialRouteCollection($request);
  }
  if ($collection
    ->count() === 0) {
    throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $this->currentPath
      ->getPath()));
  }
  $collection = $this
    ->applyRouteFilters($collection, $request);
  $collection = $this
    ->applyFitOrder($collection);
  if ($ret = $this
    ->matchCollection(rawurldecode($this->currentPath
    ->getPath($request)), $collection)) {
    return $this
      ->applyRouteEnhancers($ret, $request);
  }
  throw 0 < count($this->allow) ? new MethodNotAllowedException(array_unique($this->allow)) : new ResourceNotFoundException(sprintf('No routes found for "%s".', $this->currentPath
    ->getPath()));
}