You are here

private function ChainRouter::doMatch in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony-cmf/routing/ChainRouter.php \Symfony\Cmf\Component\Routing\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:

Return value

array An array of parameters

Throws

ResourceNotFoundException If no router matched.

2 calls to ChainRouter::doMatch()
ChainRouter::match in vendor/symfony-cmf/routing/ChainRouter.php
Loops through all routes and tries to match the passed url.
ChainRouter::matchRequest in vendor/symfony-cmf/routing/ChainRouter.php
Loops through all routes and tries to match the passed request.

File

vendor/symfony-cmf/routing/ChainRouter.php, line 171

Class

ChainRouter
The ChainRouter allows to combine several routers to try in a defined order.

Namespace

Symfony\Cmf\Component\Routing

Code

private function doMatch($url, Request $request = null) {
  $methodNotAllowed = null;
  $requestForMatching = $request;
  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 (empty($requestForMatching)) {
          $requestForMatching = Request::create($url);
        }
        return $router
          ->matchRequest($requestForMatching);
      }

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

      // Needs special care
    } catch (MethodNotAllowedException $e) {
      if ($this->logger) {
        $this->logger
          ->debug('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}");
}