|
19 | 19 | use Symfony\Component\TypeInfo\Type\BuiltinType;
|
20 | 20 | use Symfony\Component\TypeInfo\Type\CollectionType;
|
21 | 21 | use Symfony\Component\TypeInfo\Type\CompositeTypeInterface;
|
| 22 | +use Symfony\Component\TypeInfo\Type\IntersectionType; |
22 | 23 | use Symfony\Component\TypeInfo\Type\NullableType;
|
23 | 24 | use Symfony\Component\TypeInfo\Type\ObjectType;
|
24 |
| -use Symfony\Component\TypeInfo\TypeIdentifier; |
| 25 | +use Symfony\Component\TypeInfo\Type\UnionType; |
25 | 26 | use Symfony\Component\TypeInfo\Type\WrappingTypeInterface;
|
| 27 | +use Symfony\Component\TypeInfo\TypeIdentifier; |
26 | 28 | use Symfony\Component\Validator\Constraints\All;
|
27 | 29 | use Symfony\Component\Validator\Constraints\NotBlank;
|
28 | 30 | use Symfony\Component\Validator\Constraints\NotNull;
|
@@ -141,7 +143,22 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
|
141 | 143 | }
|
142 | 144 |
|
143 | 145 | $type = $types;
|
144 |
| - $nullable = $type->isNullable(); |
| 146 | + |
| 147 | + // BC layer for type-info < 7.2 |
| 148 | + if (!class_exists(NullableType::class)) { |
| 149 | + $nullable = false; |
| 150 | + |
| 151 | + if ($type instanceof UnionType && $type->isNullable()) { |
| 152 | + $nullable = true; |
| 153 | + $type = $type->asNonNullable(); |
| 154 | + } |
| 155 | + } else { |
| 156 | + $nullable = $type->isNullable(); |
| 157 | + |
| 158 | + if ($type instanceof NullableType) { |
| 159 | + $type = $type->getWrappedType(); |
| 160 | + } |
| 161 | + } |
145 | 162 |
|
146 | 163 | if ($type instanceof NullableType) {
|
147 | 164 | $type = $type->getWrappedType();
|
@@ -194,6 +211,25 @@ private function getTypeConstraintLegacy(string $builtinType, PropertyInfoType $
|
194 | 211 |
|
195 | 212 | private function getTypeConstraint(TypeInfoType $type): ?Type
|
196 | 213 | {
|
| 214 | + // BC layer for type-info < 7.2 |
| 215 | + if (!interface_exists(CompositeTypeInterface::class)) { |
| 216 | + if ($type instanceof UnionType || $type instanceof IntersectionType) { |
| 217 | + return ($type->isA(TypeIdentifier::INT) || $type->isA(TypeIdentifier::FLOAT) || $type->isA(TypeIdentifier::STRING) || $type->isA(TypeIdentifier::BOOL)) ? new Type(['type' => 'scalar']) : null; |
| 218 | + } |
| 219 | + |
| 220 | + $baseType = $type->getBaseType(); |
| 221 | + |
| 222 | + if ($baseType instanceof ObjectType) { |
| 223 | + return new Type(['type' => $baseType->getClassName()]); |
| 224 | + } |
| 225 | + |
| 226 | + if (TypeIdentifier::MIXED !== $baseType->getTypeIdentifier()) { |
| 227 | + return new Type(['type' => $baseType->getTypeIdentifier()->value]); |
| 228 | + } |
| 229 | + |
| 230 | + return null; |
| 231 | + } |
| 232 | + |
197 | 233 | if ($type instanceof CompositeTypeInterface) {
|
198 | 234 | return $type->isIdentifiedBy(
|
199 | 235 | TypeIdentifier::INT,
|
|
0 commit comments