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

@@ -28,7 +28,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
/**
* @param \Traversable<EnvVarLoaderInterface>|null $loaders
*/
public function __construct(ContainerInterface $container, \Traversable $loaders = null)
public function __construct(ContainerInterface $container, ?\Traversable $loaders = null)
{
$this->container = $container;
$this->loaders = $loaders ?? new \ArrayIterator();
@@ -66,7 +66,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('key' === $prefix) {
if (false === $i) {
throw new RuntimeException(sprintf('Invalid env "key:%s": a key specifier should be provided.', $name));
throw new RuntimeException(\sprintf('Invalid env "key:%s": a key specifier should be provided.', $name));
}
$next = substr($name, $i + 1);
@@ -74,11 +74,11 @@ class EnvVarProcessor implements EnvVarProcessorInterface
$array = $getEnv($next);
if (!\is_array($array)) {
throw new RuntimeException(sprintf('Resolved value of "%s" did not result in an array value.', $next));
throw new RuntimeException(\sprintf('Resolved value of "%s" did not result in an array value.', $next));
}
if (!isset($array[$key]) && !\array_key_exists($key, $array)) {
throw new EnvNotFoundException(sprintf('Key "%s" not found in %s (resolved from "%s").', $key, json_encode($array), $next));
throw new EnvNotFoundException(\sprintf('Key "%s" not found in %s (resolved from "%s").', $key, json_encode($array), $next));
}
return $array[$key];
@@ -86,7 +86,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('enum' === $prefix) {
if (false === $i) {
throw new RuntimeException(sprintf('Invalid env "enum:%s": a "%s" class-string should be provided.', $name, \BackedEnum::class));
throw new RuntimeException(\sprintf('Invalid env "enum:%s": a "%s" class-string should be provided.', $name, \BackedEnum::class));
}
$next = substr($name, $i + 1);
@@ -94,14 +94,14 @@ class EnvVarProcessor implements EnvVarProcessorInterface
$backedEnumValue = $getEnv($next);
if (!\is_string($backedEnumValue) && !\is_int($backedEnumValue)) {
throw new RuntimeException(sprintf('Resolved value of "%s" did not result in a string or int value.', $next));
throw new RuntimeException(\sprintf('Resolved value of "%s" did not result in a string or int value.', $next));
}
if (!is_subclass_of($backedEnumClassName, \BackedEnum::class)) {
throw new RuntimeException(sprintf('"%s" is not a "%s".', $backedEnumClassName, \BackedEnum::class));
throw new RuntimeException(\sprintf('"%s" is not a "%s".', $backedEnumClassName, \BackedEnum::class));
}
return $backedEnumClassName::tryFrom($backedEnumValue) ?? throw new RuntimeException(sprintf('Enum value "%s" is not backed by "%s".', $backedEnumValue, $backedEnumClassName));
return $backedEnumClassName::tryFrom($backedEnumValue) ?? throw new RuntimeException(\sprintf('Enum value "%s" is not backed by "%s".', $backedEnumValue, $backedEnumClassName));
}
if ('defined' === $prefix) {
@@ -114,14 +114,14 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('default' === $prefix) {
if (false === $i) {
throw new RuntimeException(sprintf('Invalid env "default:%s": a fallback parameter should be provided.', $name));
throw new RuntimeException(\sprintf('Invalid env "default:%s": a fallback parameter should be provided.', $name));
}
$next = substr($name, $i + 1);
$default = substr($name, 0, $i);
if ('' !== $default && !$this->container->hasParameter($default)) {
throw new RuntimeException(sprintf('Invalid env fallback in "default:%s": parameter "%s" not found.', $name, $default));
throw new RuntimeException(\sprintf('Invalid env fallback in "default:%s": parameter "%s" not found.', $name, $default));
}
try {
@@ -139,10 +139,10 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('file' === $prefix || 'require' === $prefix) {
if (!\is_scalar($file = $getEnv($name))) {
throw new RuntimeException(sprintf('Invalid file name: env var "%s" is non-scalar.', $name));
throw new RuntimeException(\sprintf('Invalid file name: env var "%s" is non-scalar.', $name));
}
if (!is_file($file)) {
throw new EnvNotFoundException(sprintf('File "%s" not found (resolved from "%s").', $file, $name));
throw new EnvNotFoundException(\sprintf('File "%s" not found (resolved from "%s").', $file, $name));
}
if ('file' === $prefix) {
@@ -164,10 +164,16 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if (false !== $i || 'string' !== $prefix) {
$env = $getEnv($name);
} elseif ('' === ($env = $_ENV[$name] ?? (str_starts_with($name, 'HTTP_') ? null : ($_SERVER[$name] ?? null)))
|| (false !== $env && false === ($env = $env ?? getenv($name) ?? false)) // null is a possible value because of thread safety issues
|| (false !== $env && false === $env ??= getenv($name) ?? false) // null is a possible value because of thread safety issues
) {
foreach ($this->loadedVars as $vars) {
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
foreach ($this->loadedVars as $i => $vars) {
if (false === $env = $vars[$name] ?? $env) {
continue;
}
if ($env instanceof \Stringable) {
$this->loadedVars[$i][$name] = $env = (string) $env;
}
if ('' !== ($env ?? '')) {
break;
}
}
@@ -185,7 +191,13 @@ class EnvVarProcessor implements EnvVarProcessorInterface
continue;
}
$this->loadedVars[] = $vars = $loader->loadEnvVars();
if (false !== ($env = ($vars[$name] ?? $env)) && '' !== $env) {
if (false === $env = $vars[$name] ?? $env) {
continue;
}
if ($env instanceof \Stringable) {
$this->loadedVars[array_key_last($this->loadedVars)][$name] = $env = (string) $env;
}
if ('' !== ($env ?? '')) {
$ended = false;
break;
}
@@ -202,7 +214,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if (false === $env) {
if (!$this->container->hasParameter("env($name)")) {
throw new EnvNotFoundException(sprintf('Environment variable not found: "%s".', $name));
throw new EnvNotFoundException(\sprintf('Environment variable not found: "%s".', $name));
}
$env = $this->container->getParameter("env($name)");
@@ -215,7 +227,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
}
if (!isset($this->getProvidedTypes()[$prefix])) {
throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
throw new RuntimeException(\sprintf('Unsupported env var prefix "%s".', $prefix));
}
if (!\in_array($prefix, ['string', 'bool', 'not', 'int', 'float'], true)) {
@@ -224,13 +236,13 @@ class EnvVarProcessor implements EnvVarProcessorInterface
}
if ('shuffle' === $prefix) {
\is_array($env) ? shuffle($env) : throw new RuntimeException(sprintf('Env var "%s" cannot be shuffled, expected array, got "%s".', $name, get_debug_type($env)));
\is_array($env) ? shuffle($env) : throw new RuntimeException(\sprintf('Env var "%s" cannot be shuffled, expected array, got "%s".', $name, get_debug_type($env)));
return $env;
}
if (null !== $env && !\is_scalar($env)) {
throw new RuntimeException(sprintf('Non-scalar env var "%s" cannot be cast to "%s".', $name, $prefix));
throw new RuntimeException(\sprintf('Non-scalar env var "%s" cannot be cast to "%s".', $name, $prefix));
}
if ('string' === $prefix) {
@@ -245,7 +257,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('int' === $prefix) {
if (null !== $env && false === $env = filter_var($env, \FILTER_VALIDATE_INT) ?: filter_var($env, \FILTER_VALIDATE_FLOAT)) {
throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to int.', $name));
throw new RuntimeException(\sprintf('Non-numeric env var "%s" cannot be cast to int.', $name));
}
return (int) $env;
@@ -253,7 +265,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('float' === $prefix) {
if (null !== $env && false === $env = filter_var($env, \FILTER_VALIDATE_FLOAT)) {
throw new RuntimeException(sprintf('Non-numeric env var "%s" cannot be cast to float.', $name));
throw new RuntimeException(\sprintf('Non-numeric env var "%s" cannot be cast to float.', $name));
}
return (float) $env;
@@ -261,7 +273,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
if ('const' === $prefix) {
if (!\defined($env)) {
throw new RuntimeException(sprintf('Env var "%s" maps to undefined constant "%s".', $name, $env));
throw new RuntimeException(\sprintf('Env var "%s" maps to undefined constant "%s".', $name, $env));
}
return \constant($env);
@@ -275,26 +287,26 @@ class EnvVarProcessor implements EnvVarProcessorInterface
$env = json_decode($env, true);
if (\JSON_ERROR_NONE !== json_last_error()) {
throw new RuntimeException(sprintf('Invalid JSON in env var "%s": ', $name).json_last_error_msg());
throw new RuntimeException(\sprintf('Invalid JSON in env var "%s": ', $name).json_last_error_msg());
}
if (null !== $env && !\is_array($env)) {
throw new RuntimeException(sprintf('Invalid JSON env var "%s": array or null expected, "%s" given.', $name, get_debug_type($env)));
throw new RuntimeException(\sprintf('Invalid JSON env var "%s": array or null expected, "%s" given.', $name, get_debug_type($env)));
}
return $env;
}
if ('url' === $prefix) {
$parsedEnv = parse_url($env);
$params = parse_url($env);
if (false === $parsedEnv) {
throw new RuntimeException(sprintf('Invalid URL in env var "%s".', $name));
if (false === $params) {
throw new RuntimeException(\sprintf('Invalid URL in env var "%s".', $name));
}
if (!isset($parsedEnv['scheme'], $parsedEnv['host'])) {
throw new RuntimeException(sprintf('Invalid URL env var "%s": schema and host expected, "%s" given.', $name, $env));
if (!isset($params['scheme'], $params['host'])) {
throw new RuntimeException(\sprintf('Invalid URL in env var "%s": scheme and host expected.', $name));
}
$parsedEnv += [
$params += [
'port' => null,
'user' => null,
'pass' => null,
@@ -303,14 +315,17 @@ class EnvVarProcessor implements EnvVarProcessorInterface
'fragment' => null,
];
// remove the '/' separator
$parsedEnv['path'] = '/' === ($parsedEnv['path'] ?? '/') ? '' : substr($parsedEnv['path'], 1);
$params['user'] = null !== $params['user'] ? rawurldecode($params['user']) : null;
$params['pass'] = null !== $params['pass'] ? rawurldecode($params['pass']) : null;
return $parsedEnv;
// remove the '/' separator
$params['path'] = '/' === ($params['path'] ?? '/') ? '' : substr($params['path'], 1);
return $params;
}
if ('query_string' === $prefix) {
$queryString = parse_url($env, \PHP_URL_QUERY) ?: $env;
$queryString = parse_url($env, \PHP_URL_QUERY) ?: (parse_url($env, \PHP_URL_SCHEME) ? '' : $env);
parse_str($queryString, $result);
return $result;
@@ -329,7 +344,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
}
if (!\is_scalar($value)) {
throw new RuntimeException(sprintf('Parameter "%s" found when resolving env var "%s" must be scalar, "%s" given.', $match[1], $name, get_debug_type($value)));
throw new RuntimeException(\sprintf('Parameter "%s" found when resolving env var "%s" must be scalar, "%s" given.', $match[1], $name, get_debug_type($value)));
}
return $value;
@@ -344,6 +359,6 @@ class EnvVarProcessor implements EnvVarProcessorInterface
return trim($env);
}
throw new RuntimeException(sprintf('Unsupported env var prefix "%s" for env name "%s".', $prefix, $name));
throw new RuntimeException(\sprintf('Unsupported env var prefix "%s" for env name "%s".', $prefix, $name));
}
}