getHostTokens example

public function getCompiledRoutes(): array
    {
        $compiledRoutes = [];
        foreach ($this->getRoutes()->all() as $name => $route) {
            $compiledRoute = $route->compile();

            $compiledRoutes[$name] = [
                $compiledRoute->getVariables(),
                $route->getDefaults(),
                $route->getRequirements(),
                $compiledRoute->getTokens(),
                $compiledRoute->getHostTokens(),
                $route->getSchemes(),
                [],
            ];
        }

        return $compiledRoutes;
    }

    public function getCompiledAliases(): array
    {
        $routes = $this->getRoutes();
        
// The following parameters are what Symfony uses in       // \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection().
      // Set the static prefix to an empty string since it is redundant to       // the matching in \Drupal\Core\Routing\RouteProvider::getRoutesByPath()       // and by skipping it we more easily make the routing case-insensitive.       '',
      $symfony_compiled->getRegex(),
      $symfony_compiled->getTokens(),
      $symfony_compiled->getPathVariables(),
      $symfony_compiled->getHostRegex(),
      $symfony_compiled->getHostTokens(),
      $symfony_compiled->getHostVariables(),
      $symfony_compiled->getVariables()
    );
  }

  /** * Returns the pattern outline. * * The pattern outline is the path pattern but normalized so that all * placeholders are the string '%'. * * @param string $path * The path for which we want the normalized outline. * * @return string * The path pattern outline. */
$defaults = $route->getDefaults();
        $variables = $compiledRoute->getVariables();

        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$route->getRequirements()$compiledRoute->getTokens()$parameters$name$referenceType$compiledRoute->getHostTokens()$route->getSchemes());
    }

    /** * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route * @throws InvalidParameterException When a parameter value for a placeholder is not correct because * it does not match the requirement */
    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        
$defaults = $route->getDefaults();
        $variables = $compiledRoute->getVariables();

        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$route->getRequirements()$compiledRoute->getTokens()$parameters$name$referenceType$compiledRoute->getHostTokens()$route->getSchemes());
    }

    /** * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route * @throws InvalidParameterException When a parameter value for a placeholder is not correct because * it does not match the requirement */
    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        
public function getCompiledRoutes(): array
    {
        $compiledRoutes = [];
        foreach ($this->getRoutes()->all() as $name => $route) {
            $compiledRoute = $route->compile();

            $compiledRoutes[$name] = [
                $compiledRoute->getVariables(),
                $route->getDefaults(),
                $route->getRequirements(),
                $compiledRoute->getTokens(),
                $compiledRoute->getHostTokens(),
                $route->getSchemes(),
                [],
            ];
        }

        return $compiledRoutes;
    }

    public function getCompiledAliases(): array
    {
        $routes = $this->getRoutes();
        
$r = new \ReflectionClass(Route::class);
        $route = $r->newInstanceArgs($arguments);

        $compiled = $route->compile();
        $this->assertEquals($prefix$compiled->getStaticPrefix()$name.' (static prefix)');
        $this->assertEquals($regexstr_replace(["\n", ' '], '', $compiled->getRegex())$name.' (regex)');
        $this->assertEquals($variables$compiled->getVariables()$name.' (variables)');
        $this->assertEquals($pathVariables$compiled->getPathVariables()$name.' (path variables)');
        $this->assertEquals($tokens$compiled->getTokens()$name.' (tokens)');
        $this->assertEquals($hostRegexstr_replace(["\n", ' '], '', $compiled->getHostRegex())$name.' (host regex)');
        $this->assertEquals($hostVariables$compiled->getHostVariables()$name.' (host variables)');
        $this->assertEquals($hostTokens$compiled->getHostTokens()$name.' (host tokens)');
    }

    public static function provideCompileWithHostData()
    {
        return [
            [
                'Route with host pattern',
                ['/hello', [][][], 'www.example.com'],
                '/hello', '{^/hello$}sD', [][][
                    ['text', '/hello'],
                ],
                
Home | Imprint | This part of the site doesn't use cookies.