private function ChainRouter::doMatch

Loops through all routers and tries to match the passed request or url.

At least the url must be provided, if a request is additionally provided the request takes precedence.

Parameters

string $url:

Request $request:

2 calls to ChainRouter::doMatch()

File

drupal/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/ChainRouter.php, line 159

Class

ChainRouter
ChainRouter

Namespace

Symfony\Cmf\Component\Routing

Code

private function doMatch($url, Request $request = null) {
  $methodNotAllowed = null;
  foreach ($this
    ->all() as $router) {
    try {

      // the request/url match logic is the same as in Symfony/Component/HttpKernel/EventListener/RouterListener.php
      // matching requests is more powerful than matching URLs only, so try that first
      if ($router instanceof RequestMatcherInterface) {
        if (null === $request) {
          $request = Request::create($url);
        }
        return $router
          ->matchRequest($request);
      }

      // every router implements the match method
      return $router
        ->match($url);
    } catch (ResourceNotFoundException $e) {
      if ($this->logger) {
        $this->logger
          ->info('Router ' . get_class($router) . ' was not able to match, message "' . $e
          ->getMessage() . '"');
      }

      // Needs special care
    } catch (MethodNotAllowedException $e) {
      if ($this->logger) {
        $this->logger
          ->info('Router ' . get_class($router) . ' throws MethodNotAllowedException with message "' . $e
          ->getMessage() . '"');
      }
      $methodNotAllowed = $e;
    }
  }
  $info = $request ? "this request\n{$request}" : "url '{$url}'";
  throw $methodNotAllowed ?: new ResourceNotFoundException("None of the routers in the chain matched {$info}");
}