class ProviderBasedGenerator

A Generator that uses a RouteProvider rather than a RouteCollection

@author Larry Garfield

Hierarchy

Expanded class hierarchy of ProviderBasedGenerator

2 files declare their use of ProviderBasedGenerator
ProviderBasedGeneratorTest.php in drupal/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/Routing/ProviderBasedGeneratorTest.php
UrlGenerator.php in drupal/core/lib/Drupal/Core/Routing/UrlGenerator.php
Contains Drupal\Core\Routing\UrlGenerator.

File

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

Namespace

Symfony\Cmf\Component\Routing
View source
class ProviderBasedGenerator extends UrlGenerator implements VersatileGeneratorInterface {

  /**
   * The route provider for this generator.
   *
   * @var RouteProviderInterface
   */
  protected $provider;
  public function __construct(RouteProviderInterface $provider, LoggerInterface $logger = null) {
    $this->provider = $provider;
    $this->logger = $logger;
  }

  /**
   * {@inheritDoc}
   */
  public function generate($name, $parameters = array(), $absolute = false) {
    if ($name instanceof SymfonyRoute) {
      $route = $name;
    }
    elseif (null === ($route = $this->provider
      ->getRouteByName($name, $parameters))) {
      throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
    }

    // the Route has a cache of its own and is not recompiled as long as it does not get modified
    $compiledRoute = $route
      ->compile();
    $hostTokens = $compiledRoute
      ->getHostTokens();
    return $this
      ->doGenerate($compiledRoute
      ->getVariables(), $route
      ->getDefaults(), $route
      ->getRequirements(), $compiledRoute
      ->getTokens(), $parameters, $name, $absolute, $hostTokens);
  }

  /**
   * Support a route object and any string as route name
   *
   * {@inheritDoc}
   */
  public function supports($name) {
    return is_string($name) || $name instanceof SymfonyRoute;
  }

  /**
   * {@inheritDoc}
   */
  public function getRouteDebugMessage($name, array $parameters = array()) {
    if ($name instanceof RouteObjectInterface) {
      return 'Route with key ' . $name
        ->getRouteKey();
    }
    if ($name instanceof SymfonyRoute) {
      return 'Route with pattern ' . $name
        ->getPattern();
    }
    return $name;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProviderBasedGenerator::$provider protected property The route provider for this generator.
ProviderBasedGenerator::generate public function Generates a URL or path for a specific route based on the given parameters. Overrides UrlGenerator::generate 2
ProviderBasedGenerator::getRouteDebugMessage public function Convert a route identifier (name, content object etc) into a string usable for logging and other debug/error messages Overrides VersatileGeneratorInterface::getRouteDebugMessage 1
ProviderBasedGenerator::supports public function Support a route object and any string as route name Overrides VersatileGeneratorInterface::supports 1
ProviderBasedGenerator::__construct public function Constructor. Overrides UrlGenerator::__construct 1
UrlGenerator::$context protected property
UrlGenerator::$decodedChars protected property This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.
UrlGenerator::$logger protected property
UrlGenerator::$routes protected property
UrlGenerator::$strictRequirements protected property
UrlGenerator::doGenerate protected function 2
UrlGenerator::getContext public function Gets the request context. Overrides RequestContextAwareInterface::getContext 1
UrlGenerator::getRelativePath public static function Returns the target path as relative reference from the base path.
UrlGenerator::isStrictRequirements public function Returns whether to throw an exception on incorrect parameters. Null means the requirements check is deactivated completely. Overrides ConfigurableRequirementsInterface::isStrictRequirements
UrlGenerator::setContext public function Sets the request context. Overrides RequestContextAwareInterface::setContext 1
UrlGenerator::setStrictRequirements public function Enables or disables the exception on incorrect parameters. Passing null will deactivate the requirements check completely. Overrides ConfigurableRequirementsInterface::setStrictRequirements
UrlGeneratorInterface::ABSOLUTE_PATH constant Generates an absolute path, e.g. "/dir/file".
UrlGeneratorInterface::ABSOLUTE_URL constant Generates an absolute URL, e.g. "http://example.com/dir/file".
UrlGeneratorInterface::NETWORK_PATH constant Generates a network path, e.g. "//example.com/dir/file". Such reference reuses the current scheme but specifies the host.
UrlGeneratorInterface::RELATIVE_PATH constant Generates a relative path based on the current request path, e.g. "../parent-file".