function CompiledUrlMatcherTrait::match
File
-
vendor/
symfony/ routing/ Matcher/ Dumper/ CompiledUrlMatcherTrait.php, line 35
Class
- CompiledUrlMatcherTrait
- @author Nicolas Grekas <p@tchwork.com>
Namespace
Symfony\Component\Routing\Matcher\DumperCode
public function match(string $pathinfo) : array {
$allow = $allowSchemes = [];
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $ret;
}
if ($allow) {
throw new MethodNotAllowedException(array_keys($allow));
}
if (!$this instanceof RedirectableUrlMatcherInterface) {
throw new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo));
}
if (!\in_array($this->context
->getMethod(), [
'HEAD',
'GET',
], true)) {
// no-op
}
elseif ($allowSchemes) {
redirect_scheme:
$scheme = $this->context
->getScheme();
$this->context
->setScheme(key($allowSchemes));
try {
if ($ret = $this->doMatch($pathinfo)) {
return $this->redirect($pathinfo, $ret['_route'], $this->context
->getScheme()) + $ret;
}
} finally {
$this->context
->setScheme($scheme);
}
}
elseif ('/' !== ($trimmedPathinfo = rtrim($pathinfo, '/') ?: '/')) {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo . '/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
}
if ($allowSchemes) {
goto redirect_scheme;
}
}
throw new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo));
}