getHostVariables example

$compiledRoute = $route->compile();
            $staticPrefix = rtrim($compiledRoute->getStaticPrefix(), '/');
            $hostRegex = $compiledRoute->getHostRegex();
            $regex = $compiledRoute->getRegex();
            if ($hasTrailingSlash = '/' !== $route->getPath()) {
                $pos = strrpos($regex, '$');
                $hasTrailingSlash = '/' === $regex[$pos - 1];
                $regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
            }

            if (!$compiledRoute->getPathVariables()) {
                $host = !$compiledRoute->getHostVariables() ? $route->getHost() : '';
                $url = $route->getPath();
                if ($hasTrailingSlash) {
                    $url = substr($url, 0, -1);
                }
                foreach ($dynamicRegex as [$hostRx$rx$prefix]) {
                    if (('' === $prefix || str_starts_with($url$prefix)) && (preg_match($rx$url) || preg_match($rx$url.'/')) && (!$host || !$hostRx || preg_match($hostRx$host))) {
                        $dynamicRegex[] = [$hostRegex$regex$staticPrefix];
                        $dynamicRoutes->add($name$route);
                        continue 2;
                    }
                }

                
$compiledRoute = $route->compile();
            $staticPrefix = rtrim($compiledRoute->getStaticPrefix(), '/');
            $hostRegex = $compiledRoute->getHostRegex();
            $regex = $compiledRoute->getRegex();
            if ($hasTrailingSlash = '/' !== $route->getPath()) {
                $pos = strrpos($regex, '$');
                $hasTrailingSlash = '/' === $regex[$pos - 1];
                $regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);
            }

            if (!$compiledRoute->getPathVariables()) {
                $host = !$compiledRoute->getHostVariables() ? $route->getHost() : '';
                $url = $route->getPath();
                if ($hasTrailingSlash) {
                    $url = substr($url, 0, -1);
                }
                foreach ($dynamicRegex as [$hostRx$rx$prefix]) {
                    if (('' === $prefix || str_starts_with($url$prefix)) && (preg_match($rx$url) || preg_match($rx$url.'/')) && (!$host || !$hostRx || preg_match($hostRx$host))) {
                        $dynamicRegex[] = [$hostRegex$regex$staticPrefix];
                        $dynamicRoutes->add($name$route);
                        continue 2;
                    }
                }

                

        $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'],
                ],
      // \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. */
Home | Imprint | This part of the site doesn't use cookies.