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

@@ -26,7 +26,7 @@ final class LazyServiceInstantiator implements InstantiatorInterface
$dumper = new LazyServiceDumper();
if (!$dumper->isProxyCandidate($definition, $asGhostObject, $id)) {
throw new InvalidArgumentException(sprintf('Cannot instantiate lazy proxy for service "%s".', $id));
throw new InvalidArgumentException(\sprintf('Cannot instantiate lazy proxy for service "%s".', $id));
}
if (!class_exists($proxyClass = $dumper->getProxyClass($definition, $asGhostObject), false)) {

View File

@@ -26,7 +26,7 @@ interface DumperInterface
* @param bool|null &$asGhostObject Set to true after the call if the proxy is a ghost object
* @param string|null $id
*/
public function isProxyCandidate(Definition $definition/* , bool &$asGhostObject = null, string $id = null */): bool;
public function isProxyCandidate(Definition $definition/* , ?bool &$asGhostObject = null, ?string $id = null */): bool;
/**
* Generates the code to be used to instantiate a proxy in the dumped factory code.
@@ -38,5 +38,5 @@ interface DumperInterface
*
* @param string|null $id
*/
public function getProxyCode(Definition $definition/* , string $id = null */): string;
public function getProxyCode(Definition $definition/* , ?string $id = null */): string;
}

View File

@@ -26,13 +26,13 @@ final class LazyServiceDumper implements DumperInterface
) {
}
public function isProxyCandidate(Definition $definition, bool &$asGhostObject = null, string $id = null): bool
public function isProxyCandidate(Definition $definition, ?bool &$asGhostObject = null, ?string $id = null): bool
{
$asGhostObject = false;
if ($definition->hasTag('proxy')) {
if (!$definition->isLazy()) {
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": setting the "proxy" tag on a service requires it to be "lazy".', $id ?? $definition->getClass()));
throw new InvalidArgumentException(\sprintf('Invalid definition for service "%s": setting the "proxy" tag on a service requires it to be "lazy".', $id ?? $definition->getClass()));
}
return true;
@@ -69,7 +69,7 @@ final class LazyServiceDumper implements DumperInterface
$instantiation = 'return';
if ($definition->isShared()) {
$instantiation .= sprintf(' $container->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true));
$instantiation .= \sprintf(' $container->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true));
}
$asGhostObject = str_contains($factoryCode, '$proxy');
@@ -85,7 +85,7 @@ final class LazyServiceDumper implements DumperInterface
EOF;
}
$factoryCode = sprintf('static fn ($proxy) => %s', $factoryCode);
$factoryCode = \sprintf('static fn ($proxy) => %s', $factoryCode);
return <<<EOF
if (true === \$lazyLoad) {
@@ -96,18 +96,18 @@ final class LazyServiceDumper implements DumperInterface
EOF;
}
public function getProxyCode(Definition $definition, string $id = null): string
public function getProxyCode(Definition $definition, ?string $id = null): string
{
if (!$this->isProxyCandidate($definition, $asGhostObject, $id)) {
throw new InvalidArgumentException(sprintf('Cannot instantiate lazy proxy for service "%s".', $id ?? $definition->getClass()));
throw new InvalidArgumentException(\sprintf('Cannot instantiate lazy proxy for service "%s".', $id ?? $definition->getClass()));
}
$proxyClass = $this->getProxyClass($definition, $asGhostObject, $class);
if ($asGhostObject) {
try {
return 'class '.$proxyClass.ProxyHelper::generateLazyGhost($class);
return (\PHP_VERSION_ID >= 80200 && $class?->isReadOnly() ? 'readonly ' : '').'class '.$proxyClass.ProxyHelper::generateLazyGhost($class);
} catch (LogicException $e) {
throw new InvalidArgumentException(sprintf('Cannot generate lazy ghost for service "%s".', $id ?? $definition->getClass()), 0, $e);
throw new InvalidArgumentException(\sprintf('Cannot generate lazy ghost for service "%s".', $id ?? $definition->getClass()), 0, $e);
}
}
$interfaces = [];
@@ -115,13 +115,13 @@ final class LazyServiceDumper implements DumperInterface
if ($definition->hasTag('proxy')) {
foreach ($definition->getTag('proxy') as $tag) {
if (!isset($tag['interface'])) {
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": the "interface" attribute is missing on a "proxy" tag.', $id ?? $definition->getClass()));
throw new InvalidArgumentException(\sprintf('Invalid definition for service "%s": the "interface" attribute is missing on a "proxy" tag.', $id ?? $definition->getClass()));
}
if (!interface_exists($tag['interface']) && !class_exists($tag['interface'], false)) {
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": several "proxy" tags found but "%s" is not an interface.', $id ?? $definition->getClass(), $tag['interface']));
throw new InvalidArgumentException(\sprintf('Invalid definition for service "%s": several "proxy" tags found but "%s" is not an interface.', $id ?? $definition->getClass(), $tag['interface']));
}
if ('object' !== $definition->getClass() && !is_a($class->name, $tag['interface'], true)) {
throw new InvalidArgumentException(sprintf('Invalid "proxy" tag for service "%s": class "%s" doesn\'t implement "%s".', $id ?? $definition->getClass(), $definition->getClass(), $tag['interface']));
throw new InvalidArgumentException(\sprintf('Invalid "proxy" tag for service "%s": class "%s" doesn\'t implement "%s".', $id ?? $definition->getClass(), $definition->getClass(), $tag['interface']));
}
$interfaces[] = new \ReflectionClass($tag['interface']);
}
@@ -135,11 +135,11 @@ final class LazyServiceDumper implements DumperInterface
try {
return (\PHP_VERSION_ID >= 80200 && $class?->isReadOnly() ? 'readonly ' : '').'class '.$proxyClass.ProxyHelper::generateLazyProxy($class, $interfaces);
} catch (LogicException $e) {
throw new InvalidArgumentException(sprintf('Cannot generate lazy proxy for service "%s".', $id ?? $definition->getClass()), 0, $e);
throw new InvalidArgumentException(\sprintf('Cannot generate lazy proxy for service "%s".', $id ?? $definition->getClass()), 0, $e);
}
}
public function getProxyClass(Definition $definition, bool $asGhostObject, \ReflectionClass &$class = null): string
public function getProxyClass(Definition $definition, bool $asGhostObject, ?\ReflectionClass &$class = null): string
{
$class = 'object' !== $definition->getClass() ? $definition->getClass() : 'stdClass';
$class = new \ReflectionClass($class);

View File

@@ -22,7 +22,7 @@ use Symfony\Component\DependencyInjection\Definition;
*/
class NullDumper implements DumperInterface
{
public function isProxyCandidate(Definition $definition, bool &$asGhostObject = null, string $id = null): bool
public function isProxyCandidate(Definition $definition, ?bool &$asGhostObject = null, ?string $id = null): bool
{
return $asGhostObject = false;
}
@@ -32,7 +32,7 @@ class NullDumper implements DumperInterface
return '';
}
public function getProxyCode(Definition $definition, string $id = null): string
public function getProxyCode(Definition $definition, ?string $id = null): string
{
return '';
}

View File

@@ -23,7 +23,7 @@ class ProxyHelper
/**
* @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context
*/
public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, bool $noBuiltin = false): ?string
public static function getTypeHint(\ReflectionFunctionAbstract $r, ?\ReflectionParameter $p = null, bool $noBuiltin = false): ?string
{
if ($p instanceof \ReflectionParameter) {
$type = $p->getType();
@@ -59,7 +59,7 @@ class ProxyHelper
return null;
}
$types[] = sprintf('(%s)', $typeHint);
$types[] = \sprintf('(%s)', $typeHint);
continue;
}