N°8834 - Add compatibility with PHP 8.4 (#819)

* N°8834 - Add compatibility with PHP 8.4

* Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
Lenaick
2026-02-26 10:36:32 +01:00
committed by GitHub
parent d4821b7edc
commit fc967c06ce
961 changed files with 12298 additions and 7130 deletions

View File

@@ -137,7 +137,7 @@ EOF;
$code .= '[ // $staticRoutes'."\n";
foreach ($staticRoutes as $path => $routes) {
$code .= sprintf(" %s => [\n", self::export($path));
$code .= \sprintf(" %s => [\n", self::export($path));
foreach ($routes as $route) {
$code .= vsprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", array_map([__CLASS__, 'export'], $route));
}
@@ -145,11 +145,11 @@ EOF;
}
$code .= "],\n";
$code .= sprintf("[ // \$regexpList%s\n],\n", $regexpCode);
$code .= \sprintf("[ // \$regexpList%s\n],\n", $regexpCode);
$code .= '[ // $dynamicRoutes'."\n";
foreach ($dynamicRoutes as $path => $routes) {
$code .= sprintf(" %s => [\n", self::export($path));
$code .= \sprintf(" %s => [\n", self::export($path));
foreach ($routes as $route) {
$code .= vsprintf(" [%s, %s, %s, %s, %s, %s, %s],\n", array_map([__CLASS__, 'export'], $route));
}
@@ -222,7 +222,12 @@ EOF;
foreach ($staticRoutes as $url => $routes) {
$compiledRoutes[$url] = [];
foreach ($routes as $name => [$route, $hasTrailingSlash]) {
$compiledRoutes[$url][] = $this->compileRoute($route, $name, (!$route->compile()->getHostVariables() ? $route->getHost() : $route->compile()->getHostRegex()) ?: null, $hasTrailingSlash, false, $conditions);
if ($route->compile()->getHostVariables()) {
$host = $route->compile()->getHostRegex();
} elseif ($host = $route->getHost()) {
$host = strtolower($host);
}
$compiledRoutes[$url][] = $this->compileRoute($route, $name, $host ?: null, $hasTrailingSlash, false, $conditions);
}
}
@@ -402,7 +407,7 @@ EOF;
$state->mark += 3 + $state->markTail + \strlen($regex) - $prefixLen;
$state->markTail = 2 + \strlen($state->mark);
$rx = sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark);
$rx = \sprintf('|%s(*:%s)', substr($regex, $prefixLen), $state->mark);
$code .= "\n .".self::export($rx);
$state->regex .= $rx;

View File

@@ -42,7 +42,7 @@ trait CompiledUrlMatcherTrait
throw new MethodNotAllowedException(array_keys($allow));
}
if (!$this instanceof RedirectableUrlMatcherInterface) {
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
throw new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo));
}
if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) {
// no-op
@@ -57,7 +57,7 @@ trait CompiledUrlMatcherTrait
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
} elseif ('' !== $trimmedPathinfo = rtrim($pathinfo, '/')) {
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
return $this->redirect($pathinfo, $ret['_route']) + $ret;
@@ -67,14 +67,14 @@ trait CompiledUrlMatcherTrait
}
}
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
throw new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo));
}
private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []): array
{
$allow = $allowSchemes = [];
$pathinfo = rawurldecode($pathinfo) ?: '/';
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$pathinfo = '' === ($pathinfo = rawurldecode($pathinfo)) ? '/' : $pathinfo;
$trimmedPathinfo = '' === ($trimmedPathinfo = rtrim($pathinfo, '/')) ? '/' : $trimmedPathinfo;
$context = $this->context;
$requestMethod = $canonicalMethod = $context->getMethod();

View File

@@ -198,6 +198,7 @@ class StaticPrefixCollection
public static function handleError(int $type, string $msg): bool
{
return str_contains($msg, 'Compilation failed: lookbehind assertion is not fixed length');
return str_contains($msg, 'Compilation failed: lookbehind assertion is not fixed length')
|| str_contains($msg, 'Compilation failed: length of lookbehind assertion is not limited');
}
}

View File

@@ -36,7 +36,7 @@ class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
foreach ($this->functions->getProvidedServices() as $function => $type) {
$functions[] = new ExpressionFunction(
$function,
static fn (...$args) => sprintf('($context->getParameter(\'_functions\')->get(%s)(%s))', var_export($function, true), implode(', ', $args)),
static fn (...$args) => \sprintf('($context->getParameter(\'_functions\')->get(%s)(%s))', var_export($function, true), implode(', ', $args)),
fn ($values, ...$args) => $values['context']->getParameter('_functions')->get($function)(...$args)
);
}

View File

@@ -41,7 +41,7 @@ abstract class RedirectableUrlMatcher extends UrlMatcher implements Redirectable
} finally {
$this->context->setScheme($scheme);
}
} elseif ('/' === $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
} elseif ('' === $trimmedPathinfo = rtrim($pathinfo, '/')) {
throw $e;
} else {
try {

View File

@@ -25,5 +25,5 @@ interface RedirectableUrlMatcherInterface
* @param string $route The route name that matched
* @param string|null $scheme The URL scheme (null to keep the current one)
*/
public function redirect(string $path, string $route, string $scheme = null): array;
public function redirect(string $path, string $route, ?string $scheme = null): array;
}

View File

@@ -63,7 +63,7 @@ class TraceableUrlMatcher extends UrlMatcher
$method = 'GET';
}
$supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$trimmedPathinfo = '' === ($trimmedPathinfo = rtrim($pathinfo, '/')) ? '/' : $trimmedPathinfo;
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
@@ -72,7 +72,7 @@ class TraceableUrlMatcher extends UrlMatcher
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo, $staticPrefix)) {
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
$this->addTrace(\sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
continue;
}
$regex = $compiledRoute->getRegex();
@@ -86,7 +86,7 @@ class TraceableUrlMatcher extends UrlMatcher
$r = new Route($route->getPath(), $route->getDefaults(), [], $route->getOptions());
$cr = $r->compile();
if (!preg_match($cr->getRegex(), $pathinfo)) {
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
$this->addTrace(\sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
continue;
}
@@ -96,7 +96,7 @@ class TraceableUrlMatcher extends UrlMatcher
$cr = $r->compile();
if (\in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
$this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
$this->addTrace(\sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue 2;
}
@@ -117,7 +117,7 @@ class TraceableUrlMatcher extends UrlMatcher
$hostMatches = [];
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
$this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
$this->addTrace(\sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
@@ -126,7 +126,7 @@ class TraceableUrlMatcher extends UrlMatcher
$status = $this->handleRouteRequirements($pathinfo, $name, $route, $attributes);
if (self::REQUIREMENT_MISMATCH === $status[0]) {
$this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name, $route);
$this->addTrace(\sprintf('Condition "%s" does not evaluate to "true"', $route->getCondition()), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
@@ -136,19 +136,19 @@ class TraceableUrlMatcher extends UrlMatcher
return $this->allow = $this->allowSchemes = [];
}
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
$this->addTrace(\sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
continue;
}
if ($route->getSchemes() && !$route->hasScheme($this->context->getScheme())) {
$this->allowSchemes = array_merge($this->allowSchemes, $route->getSchemes());
$this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes (%s)', $this->context->getScheme(), implode(', ', $route->getSchemes())), self::ROUTE_ALMOST_MATCHES, $name, $route);
$this->addTrace(\sprintf('Scheme "%s" does not match any of the required schemes (%s)', $this->context->getScheme(), implode(', ', $route->getSchemes())), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
if ($requiredMethods && !\in_array($method, $requiredMethods)) {
$this->allow = array_merge($this->allow, $requiredMethods);
$this->addTrace(sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route);
$this->addTrace(\sprintf('Method "%s" does not match any of the required methods (%s)', $this->context->getMethod(), implode(', ', $requiredMethods)), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
@@ -160,7 +160,7 @@ class TraceableUrlMatcher extends UrlMatcher
return [];
}
private function addTrace(string $log, int $level = self::ROUTE_DOES_NOT_MATCH, string $name = null, Route $route = null): void
private function addTrace(string $log, int $level = self::ROUTE_DOES_NOT_MATCH, ?string $name = null, ?Route $route = null): void
{
$this->traces[] = [
'log' => $log,

View File

@@ -78,8 +78,9 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
public function match(string $pathinfo): array
{
$this->allow = $this->allowSchemes = [];
$pathinfo = '' === ($pathinfo = rawurldecode($pathinfo)) ? '/' : $pathinfo;
if ($ret = $this->matchCollection(rawurldecode($pathinfo) ?: '/', $this->routes)) {
if ($ret = $this->matchCollection($pathinfo, $this->routes)) {
return $ret;
}
@@ -87,7 +88,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
throw new NoConfigurationException();
}
throw 0 < \count($this->allow) ? new MethodNotAllowedException(array_unique($this->allow)) : new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
throw 0 < \count($this->allow) ? new MethodNotAllowedException(array_unique($this->allow)) : new ResourceNotFoundException(\sprintf('No routes found for "%s".', $pathinfo));
}
public function matchRequest(Request $request): array
@@ -125,7 +126,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
$method = 'GET';
}
$supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
$trimmedPathinfo = '' === ($trimmedPathinfo = rtrim($pathinfo, '/')) ? '/' : $trimmedPathinfo;
foreach ($routes as $name => $route) {
$compiledRoute = $route->compile();
@@ -225,7 +226,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
$routeParameters = func_get_arg(3);
if (!\is_array($routeParameters)) {
throw new \TypeError(sprintf('"%s": Argument $routeParameters is expected to be an array, got "%s".', __METHOD__, get_debug_type($routeParameters)));
throw new \TypeError(\sprintf('"%s": Argument $routeParameters is expected to be an array, got "%s".', __METHOD__, get_debug_type($routeParameters)));
}
}