public function FirstEntryFinalMatcher::matchRequest

Implements Drupal\Core\Routing\FinalMatcherInterface::matchRequest().

Overrides FinalMatcherInterface::matchRequest

File

drupal/core/lib/Drupal/Core/Routing/FirstEntryFinalMatcher.php, line 46
Definition of Drupal\Core\Routing\FirstEntryFinalMatcher.

Class

FirstEntryFinalMatcher
Final matcher that simply returns the first item in the remaining routes.

Namespace

Drupal\Core\Routing

Code

public function matchRequest(Request $request) {

  // Return whatever the first route in the collection is.
  foreach ($this->routes as $name => $route) {
    $path = '/' . $request->attributes
      ->get('system_path');
    $route
      ->setOption('compiler_class', '\\Drupal\\Core\\Routing\\RouteCompiler');
    $compiled = $route
      ->compile();
    preg_match($compiled
      ->getRegex(), $path, $matches);
    $route
      ->setOption('_name', $name);
    return array_merge($this
      ->mergeDefaults($matches, $route
      ->getDefaults()), array(
      '_route' => $route,
    ));
  }
}