|
21 | 21 | use ApiPlatform\Metadata\ResourceClassResolverInterface;
|
22 | 22 | use ApiPlatform\Metadata\UrlGeneratorInterface;
|
23 | 23 | use ApiPlatform\Metadata\Util\ClassInfoTrait;
|
| 24 | +use ApiPlatform\Metadata\Util\TypeHelper; |
24 | 25 | use ApiPlatform\Serializer\AbstractItemNormalizer;
|
25 | 26 | use ApiPlatform\Serializer\CacheKeyTrait;
|
26 | 27 | use ApiPlatform\Serializer\ContextTrait;
|
|
39 | 40 | use Symfony\Component\TypeInfo\Type\CollectionType;
|
40 | 41 | use Symfony\Component\TypeInfo\Type\CompositeTypeInterface;
|
41 | 42 | use Symfony\Component\TypeInfo\Type\ObjectType;
|
42 |
| -use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; |
43 | 43 |
|
44 | 44 | /**
|
45 | 45 | * Converts between objects and array including HAL metadata.
|
@@ -212,17 +212,8 @@ private function getComponents(object $object, ?string $format, array $context):
|
212 | 212 | $isOne = $className && $this->resourceClassResolver->isResourceClass($className);
|
213 | 213 | }
|
214 | 214 | } elseif ($type instanceof Type) {
|
215 |
| - $typeIsCollection = function (Type $type) use (&$typeIsCollection, &$valueType): bool { |
216 |
| - return match (true) { |
217 |
| - $type instanceof CollectionType => null !== $valueType = $type->getCollectionValueType(), |
218 |
| - $type instanceof WrappingTypeInterface => $type->wrappedTypeIsSatisfiedBy($typeIsCollection), |
219 |
| - $type instanceof CompositeTypeInterface => $type->composedTypesAreSatisfiedBy($typeIsCollection), |
220 |
| - default => false, |
221 |
| - }; |
222 |
| - }; |
223 |
| - |
224 |
| - if ($type->isSatisfiedBy($typeIsCollection)) { |
225 |
| - $isMany = $valueType->isSatisfiedBy($typeIsResourceClass); |
| 215 | + if ($type->isSatisfiedBy(fn ($t) => $t instanceof CollectionType)) { |
| 216 | + $isMany = TypeHelper::getCollectionValueType($type)?->isSatisfiedBy($typeIsResourceClass); |
226 | 217 | } else {
|
227 | 218 | $isOne = $type->isSatisfiedBy($typeIsResourceClass);
|
228 | 219 | }
|
|
0 commit comments