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

Breadcrumb

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

function CompiledUrlMatcherTrait::doMatch

1 call to CompiledUrlMatcherTrait::doMatch()
CompiledUrlMatcherTrait::match in vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php

File

vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php, line 73

Class

CompiledUrlMatcherTrait
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\Routing\Matcher\Dumper

Code

private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []) : array {
    $allow = $allowSchemes = [];
    $pathinfo = rawurldecode($pathinfo) ?: '/';
    $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
    $context = $this->context;
    $requestMethod = $canonicalMethod = $context->getMethod();
    if ($this->matchHost) {
        $host = strtolower($context->getHost());
    }
    if ('HEAD' === $requestMethod) {
        $canonicalMethod = 'GET';
    }
    $supportsRedirections = 'GET' === $canonicalMethod && $this instanceof RedirectableUrlMatcherInterface;
    foreach ($this->staticRoutes[$trimmedPathinfo] ?? [] as [
        $ret,
        $requiredHost,
        $requiredMethods,
        $requiredSchemes,
        $hasTrailingSlash,
        ,
        $condition,
    ]) {
        if ($requiredHost) {
            if ('{' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
                continue;
            }
            if ('{' === $requiredHost[0] && $hostMatches) {
                $hostMatches['_route'] = $ret['_route'];
                $ret = $this->mergeDefaults($hostMatches, $ret);
            }
        }
        if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ??= $this->request ?: $this->createRequest($pathinfo) : null, $ret)) {
            continue;
        }
        if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
            if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
                return $allow = $allowSchemes = [];
            }
            continue;
        }
        $hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
        if ($hasRequiredScheme && $requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
            $allow += $requiredMethods;
            continue;
        }
        if (!$hasRequiredScheme) {
            $allowSchemes += $requiredSchemes;
            continue;
        }
        return $ret;
    }
    $matchedPathinfo = $this->matchHost ? $host . '.' . $pathinfo : $pathinfo;
    foreach ($this->regexpList as $offset => $regex) {
        while (preg_match($regex, $matchedPathinfo, $matches)) {
            foreach ($this->dynamicRoutes[$m = (int) $matches['MARK']] as [
                $ret,
                $vars,
                $requiredMethods,
                $requiredSchemes,
                $hasTrailingSlash,
                $hasTrailingVar,
                $condition,
            ]) {
                if (0 === $condition) {
                    // marks the last route in the regexp
                    continue 3;
                }
                $hasTrailingVar = $trimmedPathinfo !== $pathinfo && $hasTrailingVar;
                if ($hasTrailingVar && ($hasTrailingSlash || null === ($n = $matches[\count($vars)] ?? null) || '/' !== ($n[-1] ?? '/')) && preg_match($regex, $this->matchHost ? $host . '.' . $trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
                    if ($hasTrailingSlash) {
                        $matches = $n;
                    }
                    else {
                        $hasTrailingVar = false;
                    }
                }
                foreach ($vars as $i => $v) {
                    if (isset($matches[1 + $i])) {
                        $ret[$v] = $matches[1 + $i];
                    }
                }
                if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ??= $this->request ?: $this->createRequest($pathinfo) : null, $ret)) {
                    continue;
                }
                if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
                    if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
                        return $allow = $allowSchemes = [];
                    }
                    continue;
                }
                if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
                    $allowSchemes += $requiredSchemes;
                    continue;
                }
                if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
                    $allow += $requiredMethods;
                    continue;
                }
                return $ret;
            }
            $regex = substr_replace($regex, 'F', $m - $offset, 1 + \strlen($m));
            $offset += \strlen($m);
        }
    }
    if ('/' === $pathinfo && !$allow && !$allowSchemes) {
        throw new NoConfigurationException();
    }
    return [];
}

API Navigation

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