Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a46f9f

Browse files
Fix support for PHP8 union types
1 parent bf2fb93 commit 6a46f9f

File tree

18 files changed

+28
-26
lines changed

18 files changed

+28
-26
lines changed

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
112112
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);
113113
}
114114

115-
$configuratorClass = $configureContainer->getNumberOfParameters() > 0 && ($type = $configureContainer->getParameters()[0]->getType()) && !$type->isBuiltin() ? $type->getName() : null;
115+
$configuratorClass = $configureContainer->getNumberOfParameters() > 0 && ($type = $configureContainer->getParameters()[0]->getType()) && !$type->isBuiltin() ? $type->getName() : null;//
116116

117117
if ($configuratorClass && !is_a(ContainerConfigurator::class, $configuratorClass, true)) {
118118
$this->configureContainer($container, $loader);

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private function generateSignature(\ReflectionClass $class): iterable
169169
if (!$parametersWithUndefinedConstants) {
170170
yield preg_replace('/^ @@.*/m', '', $m);
171171
} else {
172+
$t = $m->getReturnType();
172173
$stack = [
173174
$m->getDocComment(),
174175
$m->getName(),
@@ -179,15 +180,16 @@ private function generateSignature(\ReflectionClass $class): iterable
179180
$m->isPrivate(),
180181
$m->isProtected(),
181182
$m->returnsReference(),
182-
$m->hasReturnType() ? $m->getReturnType()->getName() : '',
183+
$t instanceof \ReflectionNamedType ? $t->getName() : (string) $t,
183184
];
184185

185186
foreach ($m->getParameters() as $p) {
186187
if (!isset($parametersWithUndefinedConstants[$p->name])) {
187188
$stack[] = (string) $p;
188189
} else {
190+
$t = $p->getType();
189191
$stack[] = $p->isOptional();
190-
$stack[] = $p->hasType() ? $p->getType()->getName() : '';
192+
$stack[] = $t instanceof \ReflectionNamedType ? $t->getName() : (string) $t;
191193
$stack[] = $p->isPassedByReference();
192194
$stack[] = $p->isVariadic();
193195
$stack[] = $p->getName();

src/Symfony/Component/DependencyInjection/Compiler/AutowireRequiredPropertiesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function processValue($value, bool $isRoot = false)
5555
continue;
5656
}
5757

58-
$type = $reflectionProperty->getType()->getName();
58+
$type = $reflectionProperty->getType()->getName();//
5959
$value->setProperty($name, new TypedReference($type, $type, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $name));
6060
}
6161

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
155155
*/
156156
private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix): void
157157
{
158-
$type = $parameter->getType()->getName();
158+
$type = $parameter->getType()->getName();//
159159

160160
if ($value instanceof Reference) {
161161
if (!$this->container->has($value = (string) $value)) {
@@ -266,7 +266,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
266266
return;
267267
}
268268

269-
$checkFunction = sprintf('is_%s', $parameter->getType()->getName());
269+
$checkFunction = sprintf('is_%s', $parameter->getType()->getName());//
270270

271271
if (!$parameter->getType()->isBuiltin() || !$checkFunction($value)) {
272272
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : get_debug_type($value), $parameter);

src/Symfony/Component/DependencyInjection/Dumper/Preloader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static function doPreload(string $class, array &$preloaded)
8888
if (\PHP_VERSION_ID >= 70400) {
8989
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
9090
if (($t = $p->getType()) && !$t->isBuiltin()) {
91-
self::doPreload($t->getName(), $preloaded);
91+
self::doPreload($t->getName(), $preloaded);//
9292
}
9393
}
9494
}
@@ -104,12 +104,12 @@ private static function doPreload(string $class, array &$preloaded)
104104
}
105105

106106
if (($t = $p->getType()) && !$t->isBuiltin()) {
107-
self::doPreload($t->getName(), $preloaded);
107+
self::doPreload($t->getName(), $preloaded);//
108108
}
109109
}
110110

111111
if (($t = $m->getReturnType()) && !$t->isBuiltin()) {
112-
self::doPreload($t->getName(), $preloaded);
112+
self::doPreload($t->getName(), $preloaded);//
113113
}
114114
}
115115
} catch (\ReflectionException $e) {

src/Symfony/Component/DependencyInjection/Exception/InvalidParameterTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ class InvalidParameterTypeException extends InvalidArgumentException
2121
{
2222
public function __construct(string $serviceId, string $type, \ReflectionParameter $parameter)
2323
{
24-
parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $parameter->getType()->getName(), $type));
24+
parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $parameter->getType()->getName(), $type));//
2525
}
2626
}

src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
3232
return null;
3333
}
3434
if (!\is_string($type)) {
35-
$name = $type->getName();
35+
$name = $type->getName();//
3636

3737
if ($type->isBuiltin()) {
3838
return $noBuiltin ? null : $name;

src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private function getEventFromTypeDeclaration(ContainerBuilder $container, string
189189
|| 1 > ($m = $r->getMethod($method))->getNumberOfParameters()
190190
|| !($type = $m->getParameters()[0]->getType())
191191
|| $type->isBuiltin()
192-
|| Event::class === ($name = $type->getName())
192+
|| Event::class === ($name = $type->getName())//
193193
) {
194194
throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
195195
}

src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbs
4848
if (!$type = $parameter->getType()) {
4949
return null;
5050
}
51-
$name = $type->getName();
51+
$name = $type->getName();//
5252

5353
if ($function instanceof \ReflectionMethod) {
5454
$lcName = strtolower($name);

src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function onControllerArguments(ControllerArgumentsEvent $event)
102102
$r = new \ReflectionFunction(\Closure::fromCallable($event->getController()));
103103
$r = $r->getParameters()[$k] ?? null;
104104

105-
if ($r && (!$r->hasType() || \in_array($r->getType()->getName(), [FlattenException::class, LegacyFlattenException::class], true))) {
105+
if ($r && (!$r->hasType() || \in_array($r->getType()->getName(), [FlattenException::class, LegacyFlattenException::class], true))) {//
106106
$arguments = $event->getArguments();
107107
$arguments[$k] = FlattenException::createFromThrowable($e);
108108
$event->setArguments($arguments);

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
232232
throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type));
233233
}
234234

235-
return [$parameters[0]->getType()->getName()];
235+
return [$parameters[0]->getType()->getName()];//
236236
}
237237

238238
private function registerReceivers(ContainerBuilder $container, array $busIds)

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function setDefault(string $option, $value)
206206
return $this;
207207
}
208208

209-
if (isset($params[0]) && null !== ($type = $params[0]->getType()) && self::class === $type->getName() && (!isset($params[1]) || (null !== ($type = $params[1]->getType()) && Options::class === $type->getName()))) {
209+
if (isset($params[0]) && null !== ($type = $params[0]->getType()) && self::class === $type->getName() && (!isset($params[1]) || (null !== ($type = $params[1]->getType()) && Options::class === $type->getName()))) {//
210210
// Store closure for later evaluation
211211
$this->nested[$option][] = $value;
212212
$this->defaults[$option] = [];
@@ -1287,6 +1287,6 @@ private function getParameterClassName(\ReflectionParameter $parameter): ?string
12871287
return null;
12881288
}
12891289

1290-
return $type->getName();
1290+
return $type->getName();//
12911291
}
12921292
}

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
429429
if (\PHP_VERSION_ID >= 70400 && preg_match('/^Typed property ([\w\\\]+)::\$(\w+) must not be accessed before initialization$/', $e->getMessage(), $matches)) {
430430
$r = new \ReflectionProperty($matches[1], $matches[2]);
431431

432-
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $r->getDeclaringClass()->getName(), $r->getName(), $r->getType()->getName()), 0, $e);
432+
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $r->getDeclaringClass()->getName(), $r->getName(), $r->getType()->getName()), 0, $e);//
433433
}
434434

435435
throw $e;

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ private function extractFromDefaultValue(string $class, string $property): ?arra
479479

480480
private function extractFromReflectionType(\ReflectionType $reflectionType, \ReflectionClass $declaringClass): Type
481481
{
482-
$phpTypeOrClass = $reflectionType->getName();
482+
$phpTypeOrClass = $reflectionType->getName();//
483483
$nullable = $reflectionType->allowsNull();
484484

485485
if (Type::BUILTIN_TYPE_ARRAY === $phpTypeOrClass) {

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ protected function denormalizeParameter(\ReflectionClass $class, \ReflectionPara
412412
{
413413
try {
414414
if (($parameterType = $parameter->getType()) && !$parameterType->isBuiltin()) {
415-
$parameterClass = $parameterType->getName();
415+
$parameterClass = $parameterType->getName();//
416416
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
417417

418418
if (!$this->serializer instanceof DenormalizerInterface) {

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $
9797
$prefix = Caster::PREFIX_VIRTUAL;
9898

9999
$a += [
100-
$prefix.'name' => $c->getName(),
100+
$prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : (string) $c,
101101
$prefix.'allowsNull' => $c->allowsNull(),
102102
$prefix.'isBuiltin' => $c->isBuiltin(),
103103
];
@@ -182,7 +182,7 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
182182

183183
if (isset($a[$prefix.'returnType'])) {
184184
$v = $a[$prefix.'returnType'];
185-
$v = $v->getName();
185+
$v = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
186186
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
187187
}
188188
if (isset($a[$prefix.'class'])) {
@@ -244,7 +244,7 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
244244
]);
245245

246246
if ($v = $c->getType()) {
247-
$a[$prefix.'typeHint'] = $v->getName();
247+
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
248248
}
249249

250250
if (isset($a[$prefix.'typeHint'])) {
@@ -323,7 +323,7 @@ public static function getSignature(array $a)
323323
if (!$param->isOptional() && $param->allowsNull()) {
324324
$signature .= '?';
325325
}
326-
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';
326+
$signature .= ($type instanceof \ReflectionNamedType ? substr(strrchr('\\'.$type->getName(), '\\'), 1) : (string) $type) .' ';
327327
}
328328
$signature .= $k;
329329

src/Symfony/Contracts/Service/ServiceLocatorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getProvidedServices(): array
8787
} else {
8888
$type = (new \ReflectionFunction($factory))->getReturnType();
8989

90-
$this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').$type->getName() : '?';
90+
$this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').$type->getName() : '?';//
9191
}
9292
}
9393
}

src/Symfony/Contracts/Service/ServiceSubscriberTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function getSubscribedServices(): array
4040
}
4141

4242
if (self::class === $method->getDeclaringClass()->name && ($returnType = $method->getReturnType()) && !$returnType->isBuiltin()) {
43-
$services[self::class.'::'.$method->name] = '?'.$returnType->getName();
43+
$services[self::class.'::'.$method->name] = '?'.$returnType->getName();//
4444
}
4545
}
4646

0 commit comments

Comments
 (0)