class FirstEntryFinalMatcher

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

This class simply matches the first remaining route.

Hierarchy

Expanded class hierarchy of FirstEntryFinalMatcher

4 files declare their use of FirstEntryFinalMatcher
FirstEntryFinalMatcherTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Routing/FirstEntryFinalMatcherTest.php
Definition of Drupal\system\Tests\Routing\NestedMatcherTest.
HttpMethodMatcherTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Routing/HttpMethodMatcherTest.php
Definition of Drupal\system\Tests\Routing\HttpMethodMMatcherTest.
MimeTypeMatcherTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Routing/MimeTypeMatcherTest.php
Contains Drupal\system\Tests\Routing\MimeTypeMatcherTest.
NestedMatcherTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Routing/NestedMatcherTest.php
Definition of Drupal\system\Tests\Routing\NestedMatcherTest.

File

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

Namespace

Drupal\Core\Routing
View source
class FirstEntryFinalMatcher implements FinalMatcherInterface {

  /**
   * The RouteCollection this matcher should match against.
   *
   * @var RouteCollection
   */
  protected $routes;

  /**
   * Sets the route collection this matcher should use.
   *
   * @param \Symfony\Component\Routing\RouteCollection $collection
   *   The collection against which to match.
   *
   * @return \Drupal\Core\Routing\FinalMatcherInterface
   *   The current matcher.
   */
  public function setCollection(RouteCollection $collection) {
    $this->routes = $collection;
    return $this;
  }

  /**
   * Implements Drupal\Core\Routing\FinalMatcherInterface::matchRequest().
   */
  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,
      ));
    }
  }

  /**
   * Get merged default parameters.
   *
   * @param array $params
   *  The parameters.
   * @param array $defaults
   *   The defaults.
   *
   * @return array
   *   Merged default parameters.
   */
  protected function mergeDefaults($params, $defaults) {
    $parameters = $defaults;
    foreach ($params as $key => $value) {
      if (!is_int($key)) {
        $parameters[$key] = $value;
      }
    }
    return $parameters;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FirstEntryFinalMatcher::$routes protected property The RouteCollection this matcher should match against.
FirstEntryFinalMatcher::matchRequest public function Implements Drupal\Core\Routing\FinalMatcherInterface::matchRequest(). Overrides FinalMatcherInterface::matchRequest
FirstEntryFinalMatcher::mergeDefaults protected function Get merged default parameters.
FirstEntryFinalMatcher::setCollection public function Sets the route collection this matcher should use. Overrides FinalMatcherInterface::setCollection