public function ChainRouter::generate

Loops through all registered routers and returns a router if one is found. It will always return the first route generated.

Overrides UrlGeneratorInterface::generate

File

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

Class

ChainRouter
ChainRouter

Namespace

Symfony\Cmf\Component\Routing

Code

public function generate($name, $parameters = array(), $absolute = false) {
  $debug = array();
  foreach ($this
    ->all() as $router) {

    // if $router does not implement ChainedRouterInterface and $name is not a string, continue
    if ($name && !$router instanceof ChainedRouterInterface) {
      if (!is_string($name)) {
        continue;
      }
    }

    // If $router implements ChainedRouterInterface but doesn't support this route name, continue
    if ($router instanceof ChainedRouterInterface && !$router
      ->supports($name)) {
      continue;
    }
    try {
      return $router
        ->generate($name, $parameters, $absolute);
    } catch (RouteNotFoundException $e) {
      $hint = $router instanceof VersatileGeneratorInterface ? $router
        ->getRouteDebugMessage($name, $parameters) : "Route '{$name}' not found";
      $debug[] = $hint;
      if ($this->logger) {
        $this->logger
          ->info('Router ' . get_class($router) . " was unable to generate route. Reason: '{$hint}': " . $e
          ->getMessage());
      }
    }
  }
  if ($debug) {
    $debug = array_unique($debug);
    $info = implode(', ', $debug);
  }
  else {
    $info = "No route '{$name}' found";
  }
  throw new RouteNotFoundException(sprintf('None of the chained routers were able to generate route: %s', $info));
}