Skip to content

Commit 2024789

Browse files
committed
[PropertyInfo] Remove deprecated code
1 parent 5c5e440 commit 2024789

31 files changed

+174
-3644
lines changed

UPGRADE-8.0.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ Console
6666

6767
* Add method `isSilent()` to `OutputInterface`
6868

69+
DoctrineBridge
70+
--------------
71+
72+
* Remove the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead
73+
74+
*Before*
75+
```php
76+
$types = $extractor->getTypes(Foo::class, 'property');
77+
```
78+
79+
*After*
80+
```php
81+
$type = $extractor->getType(Foo::class, 'property');
82+
```
83+
6984
HttpClient
7085
----------
7186

@@ -91,6 +106,107 @@ OptionsResolver
91106
});
92107
```
93108

109+
PropertyInfo
110+
------------
111+
112+
* Remove the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead
113+
114+
*Before*
115+
```php
116+
$types = $extractor->getTypes(Foo::class, 'property');
117+
```
118+
119+
*After*
120+
```php
121+
$type = $extractor->getType(Foo::class, 'property');
122+
```
123+
124+
* Remove the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead
125+
126+
*Before*
127+
```php
128+
$types = $extractor->getTypesFromConstructor(Foo::class, 'property');
129+
```
130+
131+
*After*
132+
```php
133+
$type = $extractor->getTypeFromConstructor(Foo::class, 'property');
134+
```
135+
136+
* Remove the `Type` class, use `Symfony\Component\TypeInfo\Type` class from `symfony/type-info` instead
137+
138+
*Before*
139+
```php
140+
use Symfony\Component\PropertyInfo\Type;
141+
142+
// create types
143+
$int = [new Type(Type::BUILTIN_TYPE_INT)];
144+
$nullableString = [new Type(Type::BUILTIN_TYPE_STRING, true)];
145+
$object = [new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class)];
146+
$boolList = [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(BUILTIN_TYPE_INT), new Type(BUILTIN_TYPE_BOOL))];
147+
$union = [new Type(Type::BUILTIN_TYPE_STRING), new Type(BUILTIN_TYPE_INT)];
148+
$intersection = [new Type(Type::BUILTIN_TYPE_OBJECT, false, \Traversable::class), new Type(Type::BUILTIN_TYPE_OBJECT, false, \Stringable::class)];
149+
150+
// test if a type is nullable
151+
$intIsNullable = $int[0]->isNullable();
152+
153+
// echo builtin types of union
154+
foreach ($union as $type) {
155+
echo $type->getBuiltinType();
156+
}
157+
158+
// test if a type represents an instance of \ArrayAccess
159+
if ($object[0]->getClassName() instanceof \ArrayAccess::class) {
160+
// ...
161+
}
162+
163+
// handle collections
164+
if ($boolList[0]->isCollection()) {
165+
$k = $boolList->getCollectionKeyTypes();
166+
$v = $boolList->getCollectionValueTypes();
167+
168+
// ...
169+
}
170+
```
171+
172+
*After*
173+
```php
174+
use Symfony\Component\TypeInfo\BuiltinType;
175+
use Symfony\Component\TypeInfo\CollectionType;
176+
use Symfony\Component\TypeInfo\Type;
177+
178+
// create types
179+
$int = Type::int();
180+
$nullableString = Type::nullable(Type::string());
181+
$object = Type::object(Foo::class);
182+
$boolList = Type::list(Type::bool());
183+
$union = Type::union(Type::string(), Type::int());
184+
$intersection = Type::intersection(Type::object(\Traversable::class), Type::object(\Stringable::class));
185+
186+
// test if a type is nullable
187+
$intIsNullable = $int->isNullable();
188+
189+
// echo builtin types of union
190+
foreach ($union->traverse() as $type) {
191+
if ($type instanceof BuiltinType) {
192+
echo $type->getTypeIdentifier()->value;
193+
}
194+
}
195+
196+
// test if a type represents an instance of \ArrayAccess
197+
if ($object->isIdentifiedBy(\ArrayAccess::class)) {
198+
// ...
199+
}
200+
201+
// handle collections
202+
if ($boolList instanceof CollectionType) {
203+
$k = $boolList->getCollectionKeyType();
204+
$v = $boolList->getCollectionValueType();
205+
206+
// ...
207+
}
208+
```
209+
94210
TwigBridge
95211
----------
96212

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
2626
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
2727
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
28-
use Symfony\Component\PropertyInfo\Type as LegacyType;
2928
use Symfony\Component\TypeInfo\Type;
3029
use Symfony\Component\TypeInfo\TypeIdentifier;
3130

@@ -161,152 +160,6 @@ public function getType(string $class, string $property, array $context = []): ?
161160
};
162161
}
163162

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-
310163
public function isReadable(string $class, string $property, array $context = []): ?bool
311164
{
312165
return null;
@@ -396,38 +249,6 @@ private function getTypeIdentifier(string $doctrineType): ?TypeIdentifier
396249
};
397250
}
398251

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-
431252
private static function getMappingValue(array|AssociationMapping|EmbeddedClassMapping|FieldMapping|JoinColumnMapping $mapping, string $key): mixed
432253
{
433254
if ($mapping instanceof AssociationMapping || $mapping instanceof EmbeddedClassMapping || $mapping instanceof FieldMapping || $mapping instanceof JoinColumnMapping) {

0 commit comments

Comments
 (0)