From dd1b61703fae220004b476f58fa380a31e8386c5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 15 Jun 2020 16:43:28 +0200 Subject: [PATCH] Fix support for PHP8 union types --- .../Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php | 2 +- .../Compiler/AutowireRequiredPropertiesPass.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php index abb220b4aa..efd99784e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php @@ -112,7 +112,7 @@ trait MicroKernelTrait throw new \LogicException(sprintf('"%s" uses "%s", but does not implement the required method "protected function configureContainer(ContainerConfigurator $c): void".', get_debug_type($this), MicroKernelTrait::class), 0, $e); } - $configuratorClass = $configureContainer->getNumberOfParameters() > 0 && ($type = $configureContainer->getParameters()[0]->getType()) && !$type->isBuiltin() ? $type->getName() : null; + $configuratorClass = $configureContainer->getNumberOfParameters() > 0 && ($type = $configureContainer->getParameters()[0]->getType()) instanceof \ReflectionNamedType && !$type->isBuiltin() ? $type->getName() : null; if ($configuratorClass && !is_a(ContainerConfigurator::class, $configuratorClass, true)) { $this->configureContainer($container, $loader); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php index 945b8c9e01..24f9c41d2b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php @@ -42,7 +42,7 @@ class AutowireRequiredPropertiesPass extends AbstractRecursivePass $properties = $value->getProperties(); foreach ($reflectionClass->getProperties() as $reflectionProperty) { - if (!$reflectionProperty->hasType()) { + if (!($type = $reflectionProperty->getType()) instanceof \ReflectionNamedType) { continue; } if (false === $doc = $reflectionProperty->getDocComment()) { @@ -55,7 +55,7 @@ class AutowireRequiredPropertiesPass extends AbstractRecursivePass continue; } - $type = $reflectionProperty->getType()->getName(); + $type = $type->getName(); $value->setProperty($name, new TypedReference($type, $type, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $name)); }