|
25 | 25 | use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; |
26 | 26 | use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; |
27 | 27 | use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; |
28 | | -use Symfony\Component\PropertyInfo\Type as LegacyType; |
29 | 28 | use Symfony\Component\TypeInfo\Type; |
30 | 29 | use Symfony\Component\TypeInfo\TypeIdentifier; |
31 | 30 |
|
@@ -161,152 +160,6 @@ public function getType(string $class, string $property, array $context = []): ? |
161 | 160 | }; |
162 | 161 | } |
163 | 162 |
|
164 | | - /** |
165 | | - * @deprecated since Symfony 7.3, use "getType" instead |
166 | | - */ |
167 | | - public function getTypes(string $class, string $property, array $context = []): ?array |
168 | | - { |
169 | | - trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); |
170 | | - |
171 | | - if (null === $metadata = $this->getMetadata($class)) { |
172 | | - return null; |
173 | | - } |
174 | | - |
175 | | - if ($metadata->hasAssociation($property)) { |
176 | | - $class = $metadata->getAssociationTargetClass($property); |
177 | | - |
178 | | - if ($metadata->isSingleValuedAssociation($property)) { |
179 | | - if ($metadata instanceof ClassMetadata) { |
180 | | - $associationMapping = $metadata->getAssociationMapping($property); |
181 | | - |
182 | | - $nullable = $this->isAssociationNullable($associationMapping); |
183 | | - } else { |
184 | | - $nullable = false; |
185 | | - } |
186 | | - |
187 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, $nullable, $class)]; |
188 | | - } |
189 | | - |
190 | | - $collectionKeyType = LegacyType::BUILTIN_TYPE_INT; |
191 | | - |
192 | | - if ($metadata instanceof ClassMetadata) { |
193 | | - $associationMapping = $metadata->getAssociationMapping($property); |
194 | | - |
195 | | - if (self::getMappingValue($associationMapping, 'indexBy')) { |
196 | | - $subMetadata = $this->entityManager->getClassMetadata(self::getMappingValue($associationMapping, 'targetEntity')); |
197 | | - |
198 | | - // Check if indexBy value is a property |
199 | | - $fieldName = self::getMappingValue($associationMapping, 'indexBy'); |
200 | | - if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) { |
201 | | - $fieldName = $subMetadata->getFieldForColumn(self::getMappingValue($associationMapping, 'indexBy')); |
202 | | - // Not a property, maybe a column name? |
203 | | - if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) { |
204 | | - // Maybe the column name is the association join column? |
205 | | - $associationMapping = $subMetadata->getAssociationMapping($fieldName); |
206 | | - |
207 | | - $indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName); |
208 | | - $subMetadata = $this->entityManager->getClassMetadata(self::getMappingValue($associationMapping, 'targetEntity')); |
209 | | - |
210 | | - // Not a property, maybe a column name? |
211 | | - if (null === ($typeOfField = $subMetadata->getTypeOfField($indexProperty))) { |
212 | | - $fieldName = $subMetadata->getFieldForColumn($indexProperty); |
213 | | - $typeOfField = $subMetadata->getTypeOfField($fieldName); |
214 | | - } |
215 | | - } |
216 | | - } |
217 | | - |
218 | | - if (!$collectionKeyType = $this->getTypeIdentifierLegacy($typeOfField)) { |
219 | | - return null; |
220 | | - } |
221 | | - } |
222 | | - } |
223 | | - |
224 | | - return [new LegacyType( |
225 | | - LegacyType::BUILTIN_TYPE_OBJECT, |
226 | | - false, |
227 | | - Collection::class, |
228 | | - true, |
229 | | - new LegacyType($collectionKeyType), |
230 | | - new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, $class) |
231 | | - )]; |
232 | | - } |
233 | | - |
234 | | - if ($metadata instanceof ClassMetadata && isset($metadata->embeddedClasses[$property])) { |
235 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, self::getMappingValue($metadata->embeddedClasses[$property], 'class'))]; |
236 | | - } |
237 | | - |
238 | | - if ($metadata->hasField($property)) { |
239 | | - $typeOfField = $metadata->getTypeOfField($property); |
240 | | - |
241 | | - if (!$builtinType = $this->getTypeIdentifierLegacy($typeOfField)) { |
242 | | - return null; |
243 | | - } |
244 | | - |
245 | | - $nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property); |
246 | | - |
247 | | - // DBAL 4 has a special fallback strategy for BINGINT (int -> string) |
248 | | - if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) { |
249 | | - return [ |
250 | | - new LegacyType(LegacyType::BUILTIN_TYPE_INT, $nullable), |
251 | | - new LegacyType(LegacyType::BUILTIN_TYPE_STRING, $nullable), |
252 | | - ]; |
253 | | - } |
254 | | - |
255 | | - $enumType = null; |
256 | | - if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) { |
257 | | - $enumType = new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, $nullable, $enumClass); |
258 | | - } |
259 | | - |
260 | | - switch ($builtinType) { |
261 | | - case LegacyType::BUILTIN_TYPE_OBJECT: |
262 | | - switch ($typeOfField) { |
263 | | - case Types::DATE_MUTABLE: |
264 | | - case Types::DATETIME_MUTABLE: |
265 | | - case Types::DATETIMETZ_MUTABLE: |
266 | | - case 'vardatetime': |
267 | | - case Types::TIME_MUTABLE: |
268 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')]; |
269 | | - |
270 | | - case Types::DATE_IMMUTABLE: |
271 | | - case Types::DATETIME_IMMUTABLE: |
272 | | - case Types::DATETIMETZ_IMMUTABLE: |
273 | | - case Types::TIME_IMMUTABLE: |
274 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, $nullable, 'DateTimeImmutable')]; |
275 | | - |
276 | | - case Types::DATEINTERVAL: |
277 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, $nullable, 'DateInterval')]; |
278 | | - } |
279 | | - |
280 | | - break; |
281 | | - case LegacyType::BUILTIN_TYPE_ARRAY: |
282 | | - switch ($typeOfField) { |
283 | | - case 'array': // DBAL < 4 |
284 | | - case 'json_array': // DBAL < 3 |
285 | | - // return null if $enumType is set, because we can't determine if collectionKeyType is string or int |
286 | | - if ($enumType) { |
287 | | - return null; |
288 | | - } |
289 | | - |
290 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, $nullable, null, true)]; |
291 | | - |
292 | | - case Types::SIMPLE_ARRAY: |
293 | | - return [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, $nullable, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $enumType ?? new LegacyType(LegacyType::BUILTIN_TYPE_STRING))]; |
294 | | - } |
295 | | - break; |
296 | | - case LegacyType::BUILTIN_TYPE_INT: |
297 | | - case LegacyType::BUILTIN_TYPE_STRING: |
298 | | - if ($enumType) { |
299 | | - return [$enumType]; |
300 | | - } |
301 | | - break; |
302 | | - } |
303 | | - |
304 | | - return [new LegacyType($builtinType, $nullable)]; |
305 | | - } |
306 | | - |
307 | | - return null; |
308 | | - } |
309 | | - |
310 | 163 | public function isReadable(string $class, string $property, array $context = []): ?bool |
311 | 164 | { |
312 | 165 | return null; |
@@ -396,38 +249,6 @@ private function getTypeIdentifier(string $doctrineType): ?TypeIdentifier |
396 | 249 | }; |
397 | 250 | } |
398 | 251 |
|
399 | | - private function getTypeIdentifierLegacy(string $doctrineType): ?string |
400 | | - { |
401 | | - return match ($doctrineType) { |
402 | | - Types::SMALLINT, |
403 | | - Types::INTEGER => LegacyType::BUILTIN_TYPE_INT, |
404 | | - Types::FLOAT => LegacyType::BUILTIN_TYPE_FLOAT, |
405 | | - Types::BIGINT, |
406 | | - Types::STRING, |
407 | | - Types::TEXT, |
408 | | - Types::GUID, |
409 | | - Types::DECIMAL => LegacyType::BUILTIN_TYPE_STRING, |
410 | | - Types::BOOLEAN => LegacyType::BUILTIN_TYPE_BOOL, |
411 | | - Types::BLOB, |
412 | | - Types::BINARY => LegacyType::BUILTIN_TYPE_RESOURCE, |
413 | | - 'object', // DBAL < 4 |
414 | | - Types::DATE_MUTABLE, |
415 | | - Types::DATETIME_MUTABLE, |
416 | | - Types::DATETIMETZ_MUTABLE, |
417 | | - 'vardatetime', |
418 | | - Types::TIME_MUTABLE, |
419 | | - Types::DATE_IMMUTABLE, |
420 | | - Types::DATETIME_IMMUTABLE, |
421 | | - Types::DATETIMETZ_IMMUTABLE, |
422 | | - Types::TIME_IMMUTABLE, |
423 | | - Types::DATEINTERVAL => LegacyType::BUILTIN_TYPE_OBJECT, |
424 | | - 'array', // DBAL < 4 |
425 | | - 'json_array', // DBAL < 3 |
426 | | - Types::SIMPLE_ARRAY => LegacyType::BUILTIN_TYPE_ARRAY, |
427 | | - default => null, |
428 | | - }; |
429 | | - } |
430 | | - |
431 | 252 | private static function getMappingValue(array|AssociationMapping|EmbeddedClassMapping|FieldMapping|JoinColumnMapping $mapping, string $key): mixed |
432 | 253 | { |
433 | 254 | if ($mapping instanceof AssociationMapping || $mapping instanceof EmbeddedClassMapping || $mapping instanceof FieldMapping || $mapping instanceof JoinColumnMapping) { |
|
0 commit comments