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:
Nicolas Grekas 2020-06-18 21:00:54 +02:00
commit 01b5b8312b
2 changed files with 3 additions and 3 deletions

View File

@ -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);

View File

@ -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));
}