Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CompiledUrlGenerator.php

class CompiledUrlGenerator

Generates URLs based on rules dumped by CompiledUrlGeneratorDumper.

Hierarchy

  • class \Symfony\Component\Routing\Generator\UrlGenerator implements \Symfony\Component\Routing\Generator\UrlGeneratorInterface, \Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface
    • class \Symfony\Component\Routing\Generator\CompiledUrlGenerator extends \Symfony\Component\Routing\Generator\UrlGenerator

Expanded class hierarchy of CompiledUrlGenerator

1 file declares its use of CompiledUrlGenerator
Router.php in vendor/symfony/routing/Router.php

File

vendor/symfony/routing/Generator/CompiledUrlGenerator.php, line 21

Namespace

Symfony\Component\Routing\Generator
View source
class CompiledUrlGenerator extends UrlGenerator {
    private array $compiledRoutes = [];
    public function __construct(array $compiledRoutes, RequestContext $context, ?LoggerInterface $logger = null, ?string $defaultLocale = null) {
        $this->compiledRoutes = $compiledRoutes;
        $this->context = $context;
        $this->logger = $logger;
    }
    public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH) : string {
        $locale = $parameters['_locale'] ?? $this->context
            ->getParameter('_locale') ?: $this->defaultLocale;
        if (null !== $locale) {
            do {
                if (($this->compiledRoutes[$name . '.' . $locale][1]['_canonical_route'] ?? null) === $name) {
                    $name .= '.' . $locale;
                    break;
                }
            } while (false !== ($locale = strstr($locale, '_', true)));
        }
        if (!isset($this->compiledRoutes[$name])) {
            throw new RouteNotFoundException(\sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
        }
        [
            $variables,
            $defaults,
            $requirements,
            $tokens,
            $hostTokens,
            $requiredSchemes,
            $deprecations,
        ] = $this->compiledRoutes[$name] + [
            6 => [],
        ];
        foreach ($deprecations as $deprecation) {
            trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']);
        }
        if (isset($defaults['_canonical_route']) && isset($defaults['_locale'])) {
            if (!\in_array('_locale', $variables, true)) {
                unset($parameters['_locale']);
            }
            elseif (!isset($parameters['_locale'])) {
                $parameters['_locale'] = $defaults['_locale'];
            }
        }
        return $this->doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CompiledUrlGenerator::$compiledRoutes private property
CompiledUrlGenerator::generate public function Generates a URL or path for a specific route based on the given parameters. Overrides UrlGenerator::generate
CompiledUrlGenerator::__construct public function Overrides UrlGenerator::__construct
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::$strictRequirements protected property
UrlGenerator::doGenerate protected function
UrlGenerator::getContext public function Gets the request context. Overrides RequestContextAwareInterface::getContext
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::QUERY_FRAGMENT_DECODED private constant
UrlGenerator::setContext public function Sets the request context. Overrides RequestContextAwareInterface::setContext
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 public constant Generates an absolute path, e.g. "/dir/file".
UrlGeneratorInterface::ABSOLUTE_URL public constant Generates an absolute URL, e.g. "http://example.com/dir/file".
UrlGeneratorInterface::NETWORK_PATH public constant Generates a network path, e.g. "//example.com/dir/file".
Such reference reuses the current scheme but specifies the host.
UrlGeneratorInterface::RELATIVE_PATH public constant Generates a relative path based on the current request path, e.g. "../parent-file".

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal