|
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;
|
| 21 | +use Symfony\Component\TypeInfo\Type\CompositeTypeInterface; |
20 | 22 | use Symfony\Component\TypeInfo\Type\IntersectionType;
|
| 23 | +use Symfony\Component\TypeInfo\Type\NullableType; |
21 | 24 | use Symfony\Component\TypeInfo\Type\ObjectType;
|
22 | 25 | use Symfony\Component\TypeInfo\Type\UnionType;
|
| 26 | +use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; |
23 | 27 | use Symfony\Component\TypeInfo\TypeIdentifier;
|
24 | 28 | use Symfony\Component\Validator\Constraints\All;
|
25 | 29 | use Symfony\Component\Validator\Constraints\NotBlank;
|
@@ -143,7 +147,23 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
|
143 | 147 | }
|
144 | 148 |
|
145 | 149 | $type = $types;
|
146 |
| - $nullable = false; |
| 150 | + |
| 151 | + // BC layer for type-info < 7.2 |
| 152 | + if (!class_exists(NullableType::class)) { |
| 153 | + $nullable = false; |
| 154 | + |
| 155 | + if ($type instanceof UnionType && $type->isNullable()) { |
| 156 | + $nullable = true; |
| 157 | + $type = $type->asNonNullable(); |
| 158 | + } |
| 159 | + } else { |
| 160 | + $nullable = $type->isNullable(); |
| 161 | + |
| 162 | + if ($type instanceof NullableType) { |
| 163 | + $type = $type->getWrappedType(); |
| 164 | + } |
| 165 | + } |
| 166 | + |
147 | 167 |
|
148 | 168 | if ($type instanceof UnionType && $type->isNullable()) {
|
149 | 169 | $nullable = true;
|
@@ -197,18 +217,46 @@ private function getTypeConstraintLegacy(string $builtinType, PropertyInfoType $
|
197 | 217 |
|
198 | 218 | private function getTypeConstraint(TypeInfoType $type): ?Type
|
199 | 219 | {
|
200 |
| - if ($type instanceof UnionType || $type instanceof IntersectionType) { |
201 |
| - return ($type->isA(TypeIdentifier::INT) || $type->isA(TypeIdentifier::FLOAT) || $type->isA(TypeIdentifier::STRING) || $type->isA(TypeIdentifier::BOOL)) ? new Type(['type' => 'scalar']) : null; |
| 220 | + // BC layer for type-info < 7.2 |
| 221 | + if (!interface_exists(CompositeTypeInterface::class)) { |
| 222 | + if ($type instanceof UnionType || $type instanceof IntersectionType) { |
| 223 | + return ($type->isA(TypeIdentifier::INT) || $type->isA(TypeIdentifier::FLOAT) || $type->isA(TypeIdentifier::STRING) || $type->isA(TypeIdentifier::BOOL)) ? new Type(['type' => 'scalar']) : null; |
| 224 | + } |
| 225 | + |
| 226 | + $baseType = $type->getBaseType(); |
| 227 | + |
| 228 | + if ($baseType instanceof ObjectType) { |
| 229 | + return new Type(['type' => $baseType->getClassName()]); |
| 230 | + } |
| 231 | + |
| 232 | + if (TypeIdentifier::MIXED !== $baseType->getTypeIdentifier()) { |
| 233 | + return new Type(['type' => $baseType->getTypeIdentifier()->value]); |
| 234 | + } |
| 235 | + |
| 236 | + return null; |
| 237 | + } |
| 238 | + |
| 239 | + if ($type instanceof CompositeTypeInterface) { |
| 240 | + return $type->isIdentifiedBy( |
| 241 | + TypeIdentifier::INT, |
| 242 | + TypeIdentifier::FLOAT, |
| 243 | + TypeIdentifier::STRING, |
| 244 | + TypeIdentifier::BOOL, |
| 245 | + TypeIdentifier::TRUE, |
| 246 | + TypeIdentifier::FALSE, |
| 247 | + ) ? new Type(['type' => 'scalar']) : null; |
202 | 248 | }
|
203 | 249 |
|
204 |
| - $baseType = $type->getBaseType(); |
| 250 | + while ($type instanceof WrappingTypeInterface) { |
| 251 | + $type = $type->getWrappedType(); |
| 252 | + } |
205 | 253 |
|
206 |
| - if ($baseType instanceof ObjectType) { |
207 |
| - return new Type(['type' => $baseType->getClassName()]); |
| 254 | + if ($type instanceof ObjectType) { |
| 255 | + return new Type(['type' => $type->getClassName()]); |
208 | 256 | }
|
209 | 257 |
|
210 |
| - if (TypeIdentifier::MIXED !== $baseType->getTypeIdentifier()) { |
211 |
| - return new Type(['type' => $baseType->getTypeIdentifier()->value]); |
| 258 | + if ($type instanceof BuiltinType && TypeIdentifier::MIXED !== $type->getTypeIdentifier()) { |
| 259 | + return new Type(['type' => $type->getTypeIdentifier()->value]); |
212 | 260 | }
|
213 | 261 |
|
214 | 262 | return null;
|
|
0 commit comments