|
16 | 16 | use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
17 | 17 | use Symfony\Component\PropertyInfo\Type as PropertyInfoType;
|
18 | 18 | use Symfony\Component\TypeInfo\Type as TypeInfoType;
|
| 19 | +use Symfony\Component\TypeInfo\Type\BuiltinType; |
19 | 20 | use Symfony\Component\TypeInfo\Type\CollectionType;
|
20 |
| -use Symfony\Component\TypeInfo\Type\IntersectionType; |
| 21 | +use Symfony\Component\TypeInfo\Type\CompositeTypeInterface; |
| 22 | +use Symfony\Component\TypeInfo\Type\NullableType; |
21 | 23 | use Symfony\Component\TypeInfo\Type\ObjectType;
|
22 |
| -use Symfony\Component\TypeInfo\Type\UnionType; |
23 | 24 | use Symfony\Component\TypeInfo\TypeIdentifier;
|
| 25 | +use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; |
24 | 26 | use Symfony\Component\Validator\Constraints\All;
|
25 | 27 | use Symfony\Component\Validator\Constraints\NotBlank;
|
26 | 28 | use Symfony\Component\Validator\Constraints\NotNull;
|
@@ -139,11 +141,10 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
|
139 | 141 | }
|
140 | 142 |
|
141 | 143 | $type = $types;
|
142 |
| - $nullable = false; |
| 144 | + $nullable = $type->isNullable(); |
143 | 145 |
|
144 |
| - if ($type instanceof UnionType && $type->isNullable()) { |
145 |
| - $nullable = true; |
146 |
| - $type = $type->asNonNullable(); |
| 146 | + if ($type instanceof NullableType) { |
| 147 | + $type = $type->getWrappedType(); |
147 | 148 | }
|
148 | 149 |
|
149 | 150 | if ($type instanceof CollectionType) {
|
@@ -193,18 +194,27 @@ private function getTypeConstraintLegacy(string $builtinType, PropertyInfoType $
|
193 | 194 |
|
194 | 195 | private function getTypeConstraint(TypeInfoType $type): ?Type
|
195 | 196 | {
|
196 |
| - if ($type instanceof UnionType || $type instanceof IntersectionType) { |
197 |
| - return ($type->isA(TypeIdentifier::INT) || $type->isA(TypeIdentifier::FLOAT) || $type->isA(TypeIdentifier::STRING) || $type->isA(TypeIdentifier::BOOL)) ? new Type(['type' => 'scalar']) : null; |
| 197 | + if ($type instanceof CompositeTypeInterface) { |
| 198 | + return $type->isIdentifiedBy( |
| 199 | + TypeIdentifier::INT, |
| 200 | + TypeIdentifier::FLOAT, |
| 201 | + TypeIdentifier::STRING, |
| 202 | + TypeIdentifier::BOOL, |
| 203 | + TypeIdentifier::TRUE, |
| 204 | + TypeIdentifier::FALSE, |
| 205 | + ) ? new Type(['type' => 'scalar']) : null; |
198 | 206 | }
|
199 | 207 |
|
200 |
| - $baseType = $type->getBaseType(); |
| 208 | + while ($type instanceof WrappingTypeInterface) { |
| 209 | + $type = $type->getWrappedType(); |
| 210 | + } |
201 | 211 |
|
202 |
| - if ($baseType instanceof ObjectType) { |
203 |
| - return new Type(['type' => $baseType->getClassName()]); |
| 212 | + if ($type instanceof ObjectType) { |
| 213 | + return new Type(['type' => $type->getClassName()]); |
204 | 214 | }
|
205 | 215 |
|
206 |
| - if (TypeIdentifier::MIXED !== $baseType->getTypeIdentifier()) { |
207 |
| - return new Type(['type' => $baseType->getTypeIdentifier()->value]); |
| 216 | + if ($type instanceof BuiltinType && TypeIdentifier::MIXED !== $type->getTypeIdentifier()) { |
| 217 | + return new Type(['type' => $type->getTypeIdentifier()->value]); |
208 | 218 | }
|
209 | 219 |
|
210 | 220 | return null;
|
|
0 commit comments