minor #37289 [5.1] Fix support for PHP8 union types (nicolas-grekas)
This PR was merged into the 5.1 branch.
Discussion
----------
[5.1] Fix support for PHP8 union types
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
Same as #37340 for 5.1
Commits
-------
dd1b61703f
Fix support for PHP8 union types
This commit is contained in:
commit
01b5b8312b
@ -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);
|
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)) {
|
if ($configuratorClass && !is_a(ContainerConfigurator::class, $configuratorClass, true)) {
|
||||||
$this->configureContainer($container, $loader);
|
$this->configureContainer($container, $loader);
|
||||||
|
@ -42,7 +42,7 @@ class AutowireRequiredPropertiesPass extends AbstractRecursivePass
|
|||||||
|
|
||||||
$properties = $value->getProperties();
|
$properties = $value->getProperties();
|
||||||
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
|
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
|
||||||
if (!$reflectionProperty->hasType()) {
|
if (!($type = $reflectionProperty->getType()) instanceof \ReflectionNamedType) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (false === $doc = $reflectionProperty->getDocComment()) {
|
if (false === $doc = $reflectionProperty->getDocComment()) {
|
||||||
@ -55,7 +55,7 @@ class AutowireRequiredPropertiesPass extends AbstractRecursivePass
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = $reflectionProperty->getType()->getName();
|
$type = $type->getName();
|
||||||
$value->setProperty($name, new TypedReference($type, $type, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $name));
|
$value->setProperty($name, new TypedReference($type, $type, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user