class MockPathMatcher

Provides a mock path matcher.

Hierarchy

Expanded class hierarchy of MockPathMatcher

File

drupal/core/modules/system/lib/Drupal/system/Tests/Routing/MockPathMatcher.php, line 14

Namespace

Drupal\system\Tests\Routing
View source
class MockPathMatcher implements InitialMatcherInterface {

  /**
   * Routes to be matched.
   *
   * @var Symfony\Component\Routing\RouteCollection
   */
  protected $routes;

  /**
   * Construct the matcher given the route collection.
   *
   * @param Symfony\Component\Routing\RouteCollection $routes
   *   The routes being matched.
   */
  public function __construct(RouteCollection $routes) {
    $this->routes = $routes;
  }

  /**
   * Matches a request against multiple routes.
   *
   * @param Request $request
   *   A Request object against which to match.
   *
   * @return RouteCollection
   *   A RouteCollection of matched routes.
   */
  public function matchRequestPartial(Request $request) {

    // For now for testing we'll just do a straight string match.
    $path = $request
      ->getPathInfo();
    $return = new RouteCollection();
    foreach ($this->routes as $name => $route) {
      if ($route
        ->getPattern() == $path) {
        $return
          ->add($name, $route);
      }
    }
    return $return;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MockPathMatcher::$routes protected property Routes to be matched.
MockPathMatcher::matchRequestPartial public function Matches a request against multiple routes. Overrides InitialMatcherInterface::matchRequestPartial
MockPathMatcher::__construct public function Construct the matcher given the route collection.