Skip to content

Commit 4a9a145

Browse files
authored
feat!: remove legacy PropertyInfo Type system (#8364)
1 parent a8af988 commit 4a9a145

62 files changed

Lines changed: 288 additions & 3387 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"symfony/http-foundation": "^6.4.14 || ^7.0 || ^8.0",
117117
"symfony/http-kernel": "^6.4.13 || ^7.0 || ^8.0",
118118
"symfony/property-access": "^6.4 || ^7.0 || ^8.0",
119-
"symfony/property-info": "^6.4 || ^7.1 || ^8.0",
119+
"symfony/property-info": "^7.1 || ^8.0",
120120
"symfony/serializer": "^6.4.37 || ^7.4.9 || ^8.0.9",
121121
"symfony/translation-contracts": "^3.3",
122122
"symfony/type-info": "^7.4 || ^8.0",

docs/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"phpstan/phpdoc-parser": "^1.15",
2323
"symfony/framework-bundle": "^7.0",
2424
"symfony/property-access": "^7.0",
25-
"symfony/property-info": "^7.0",
25+
"symfony/property-info": "^7.1 || ^8.0",
2626
"symfony/runtime": "^7.0",
2727
"symfony/security-bundle": "^7.0",
2828
"symfony/type-info": "^7.3-dev",

src/Doctrine/Odm/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"api-platform/serializer": "^5.0@alpha",
3131
"api-platform/state": "^5.0@alpha",
3232
"doctrine/mongodb-odm": "^2.10",
33-
"symfony/property-info": "^6.4 || ^7.1 || ^8.0",
33+
"symfony/property-info": "^7.1 || ^8.0",
3434
"symfony/type-info": "^7.3 || ^8.0"
3535
},
3636
"require-dev": {

src/Doctrine/Orm/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"symfony/framework-bundle": "^6.4 || ^7.0 || ^8.0",
4242
"symfony/property-access": "^6.4 || ^7.0 || ^8.0",
4343
"symfony/serializer": "^6.4 || ^7.0 || ^8.0",
44-
"symfony/property-info": "^6.4 || ^7.1 || ^8.0",
44+
"symfony/property-info": "^7.1 || ^8.0",
4545
"symfony/uid": "^6.4 || ^7.0 || ^8.0",
4646
"symfony/validator": "^6.4.11 || ^7.0 || ^8.0",
4747
"symfony/yaml": "^6.4 || ^7.0 || ^8.0",

src/Elasticsearch/Filter/AbstractFilter.php

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2020
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2121
use ApiPlatform\Metadata\ResourceClassResolverInterface;
22-
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
23-
use Symfony\Component\PropertyInfo\Type as LegacyType;
2422
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
2523
use Symfony\Component\TypeInfo\Type;
2624
use Symfony\Component\TypeInfo\Type\CollectionType;
@@ -81,10 +79,6 @@ protected function hasProperty(string $resourceClass, string $property): bool
8179
*/
8280
protected function getMetadata(string $resourceClass, string $property): array
8381
{
84-
if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
85-
return $this->getLegacyMetadata($resourceClass, $property);
86-
}
87-
8882
$noop = [null, null, null, null];
8983

9084
if (!$this->hasProperty($resourceClass, $property)) {
@@ -176,95 +170,4 @@ protected function getMetadata(string $resourceClass, string $property): array
176170

177171
return [$type, $hasAssociation, $currentResourceClass, $currentProperty];
178172
}
179-
180-
protected function getLegacyMetadata(string $resourceClass, string $property): array
181-
{
182-
$noop = [null, null, null, null];
183-
184-
if (!$this->hasProperty($resourceClass, $property)) {
185-
return $noop;
186-
}
187-
188-
$properties = explode('.', $property);
189-
$totalProperties = \count($properties);
190-
$currentResourceClass = $resourceClass;
191-
$hasAssociation = false;
192-
$currentProperty = null;
193-
$type = null;
194-
195-
foreach ($properties as $index => $currentProperty) {
196-
try {
197-
$propertyMetadata = $this->propertyMetadataFactory->create($currentResourceClass, $currentProperty);
198-
} catch (PropertyNotFoundException) {
199-
return $noop;
200-
}
201-
202-
$types = $propertyMetadata->getBuiltinTypes();
203-
204-
if (null === $types) {
205-
return $noop;
206-
}
207-
208-
++$index;
209-
210-
// check each type before deciding if it's noop or not
211-
// e.g: maybe the first type is noop, but the second is valid
212-
$isNoop = false;
213-
214-
foreach ($types as $type) {
215-
$builtinType = $type->getBuiltinType();
216-
217-
if (LegacyType::BUILTIN_TYPE_OBJECT !== $builtinType && LegacyType::BUILTIN_TYPE_ARRAY !== $builtinType) {
218-
if ($totalProperties === $index) {
219-
break 2;
220-
}
221-
222-
$isNoop = true;
223-
224-
continue;
225-
}
226-
227-
if ($type->isCollection() && null === $type = $type->getCollectionValueTypes()[0] ?? null) {
228-
$isNoop = true;
229-
230-
continue;
231-
}
232-
233-
if (LegacyType::BUILTIN_TYPE_ARRAY === $builtinType && LegacyType::BUILTIN_TYPE_OBJECT !== $type->getBuiltinType()) {
234-
if ($totalProperties === $index) {
235-
break 2;
236-
}
237-
238-
$isNoop = true;
239-
240-
continue;
241-
}
242-
243-
if (null === $className = $type->getClassName()) {
244-
$isNoop = true;
245-
246-
continue;
247-
}
248-
249-
if ($isResourceClass = $this->resourceClassResolver->isResourceClass($className)) {
250-
$currentResourceClass = $className;
251-
} elseif ($totalProperties !== $index) {
252-
$isNoop = true;
253-
254-
continue;
255-
}
256-
257-
$hasAssociation = $totalProperties === $index && $isResourceClass;
258-
$isNoop = false;
259-
260-
break;
261-
}
262-
263-
if ($isNoop) {
264-
return $noop;
265-
}
266-
}
267-
268-
return [$type, $hasAssociation, $currentResourceClass, $currentProperty];
269-
}
270173
}

src/Elasticsearch/Filter/AbstractSearchFilter.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2222
use ApiPlatform\Metadata\ResourceClassResolverInterface;
2323
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
24-
use Symfony\Component\PropertyInfo\Type as LegacyType;
2524
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
2625
use Symfony\Component\TypeInfo\Type;
2726
use Symfony\Component\TypeInfo\Type\WrappingTypeInterface;
@@ -110,27 +109,8 @@ public function getDescription(string $resourceClass): array
110109
*/
111110
abstract protected function getQuery(string $property, array $values, ?string $nestedPath): array;
112111

113-
protected function getPhpType(LegacyType|Type $type): string
112+
protected function getPhpType(Type $type): string
114113
{
115-
if ($type instanceof LegacyType) {
116-
switch ($builtinType = $type->getBuiltinType()) {
117-
case LegacyType::BUILTIN_TYPE_ARRAY:
118-
case LegacyType::BUILTIN_TYPE_INT:
119-
case LegacyType::BUILTIN_TYPE_FLOAT:
120-
case LegacyType::BUILTIN_TYPE_BOOL:
121-
case LegacyType::BUILTIN_TYPE_STRING:
122-
return $builtinType;
123-
case LegacyType::BUILTIN_TYPE_OBJECT:
124-
if (null !== ($className = $type->getClassName()) && is_a($className, \DateTimeInterface::class, true)) {
125-
return \DateTimeInterface::class;
126-
}
127-
128-
// no break
129-
default:
130-
return 'string';
131-
}
132-
}
133-
134114
if ($type->isIdentifiedBy(TypeIdentifier::ARRAY, TypeIdentifier::INT, TypeIdentifier::FLOAT, TypeIdentifier::BOOL, TypeIdentifier::STRING)) {
135115
while ($type instanceof WrappingTypeInterface) {
136116
$type = $type->getWrappedType();
@@ -178,22 +158,8 @@ protected function getIdentifierValue(string $iri, string $property): mixed
178158
return $iri;
179159
}
180160

181-
protected function hasValidValues(array $values, LegacyType|Type $type): bool
161+
protected function hasValidValues(array $values, Type $type): bool
182162
{
183-
if ($type instanceof LegacyType) {
184-
foreach ($values as $value) {
185-
if (
186-
null !== $value
187-
&& LegacyType::BUILTIN_TYPE_INT === $type->getBuiltinType()
188-
&& false === filter_var($value, \FILTER_VALIDATE_INT)
189-
) {
190-
return false;
191-
}
192-
}
193-
194-
return true;
195-
}
196-
197163
foreach ($values as $value) {
198164
if (
199165
null !== $value

src/Elasticsearch/Util/FieldDatatypeTrait.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
1818
use ApiPlatform\Metadata\ResourceClassResolverInterface;
1919
use ApiPlatform\Metadata\Util\TypeHelper;
20-
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
21-
use Symfony\Component\PropertyInfo\Type as LegacyType;
2220
use Symfony\Component\TypeInfo\Type;
2321
use Symfony\Component\TypeInfo\Type\ObjectType;
2422

@@ -66,35 +64,6 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
6664
return null;
6765
}
6866

69-
if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
70-
$types = $propertyMetadata->getBuiltinTypes() ?? [];
71-
72-
foreach ($types as $type) {
73-
if (
74-
LegacyType::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
75-
&& null !== ($nextResourceClass = $type->getClassName())
76-
&& $this->resourceClassResolver->isResourceClass($nextResourceClass)
77-
) {
78-
$nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));
79-
80-
return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
81-
}
82-
83-
if (
84-
null !== ($type = $type->getCollectionValueTypes()[0] ?? null)
85-
&& LegacyType::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
86-
&& null !== ($className = $type->getClassName())
87-
&& $this->resourceClassResolver->isResourceClass($className)
88-
) {
89-
$nestedPath = $this->getNestedFieldPath($className, implode('.', $properties));
90-
91-
return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath";
92-
}
93-
}
94-
95-
return null;
96-
}
97-
9867
$type = $propertyMetadata->getNativeType();
9968

10069
if (null === $type) {

src/Elasticsearch/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"symfony/cache": "^6.4 || ^7.0 || ^8.0",
3232
"symfony/console": "^6.4 || ^7.0 || ^8.0",
3333
"symfony/property-access": "^6.4 || ^7.0 || ^8.0",
34-
"symfony/property-info": "^6.4 || ^7.1 || ^8.0",
34+
"symfony/property-info": "^7.1 || ^8.0",
3535
"symfony/serializer": "^6.4 || ^7.0 || ^8.0",
3636
"symfony/type-info": "^7.3 || ^8.0",
3737
"symfony/uid": "^6.4 || ^7.0 || ^8.0"

src/GraphQl/Resolver/Factory/ResolverFactory.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use ApiPlatform\State\ProviderInterface;
2828
use GraphQL\Type\Definition\ResolveInfo;
2929
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
30-
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
3130
use Symfony\Component\TypeInfo\Type\CollectionType;
3231

3332
class ResolverFactory implements ResolverFactoryInterface
@@ -66,20 +65,11 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul
6665

6766
$propertyMetadata = $rootClass ? $propertyMetadataFactory?->create($rootClass, $info->fieldName) : null;
6867

69-
if (method_exists(PropertyInfoExtractor::class, 'getType')) {
70-
$type = $propertyMetadata?->getNativeType();
68+
$type = $propertyMetadata?->getNativeType();
7169

72-
// Data already fetched and normalized (field or nested resource)
73-
if ($body || null === $resourceClass || ($type && !$type->isSatisfiedBy(static fn ($t) => $t instanceof CollectionType))) {
74-
return $body;
75-
}
76-
} else {
77-
$type = $propertyMetadata?->getBuiltinTypes()[0] ?? null;
78-
79-
// Data already fetched and normalized (field or nested resource)
80-
if ($body || null === $resourceClass || ($type && !$type->isCollection())) {
81-
return $body;
82-
}
70+
// Data already fetched and normalized (field or nested resource)
71+
if ($body || null === $resourceClass || ($type && !$type->isSatisfiedBy(static fn ($t) => $t instanceof CollectionType))) {
72+
return $body;
8373
}
8474
}
8575

src/GraphQl/Tests/Type/FieldsBuilderTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,6 @@ public function testGetResourceObjectTypeFields(string $resourceClass, Operation
485485
});
486486

487487
$typeConverter = new class implements TypeConverterInterface {
488-
public function convertType(\Symfony\Component\PropertyInfo\Type $type, bool $input, Operation $rootOperation, string $resourceClass, string $rootResource, ?string $property, int $depth): GraphQLType|string|null
489-
{
490-
return null;
491-
}
492-
493488
public function resolveType(string $type): ?GraphQLType
494489
{
495490
return null;

0 commit comments

Comments
 (0)