16
16
use ApiPlatform \Metadata \Exception \PropertyNotFoundException ;
17
17
use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
18
18
use ApiPlatform \Metadata \ResourceClassResolverInterface ;
19
+ use ApiPlatform \Metadata \Util \TypeHelper ;
19
20
use Symfony \Component \PropertyInfo \PropertyInfoExtractor ;
20
21
use Symfony \Component \PropertyInfo \Type as LegacyType ;
21
22
use Symfony \Component \TypeInfo \Type ;
22
- use Symfony \Component \TypeInfo \Type \CollectionType ;
23
- use Symfony \Component \TypeInfo \Type \CompositeTypeInterface ;
24
23
use Symfony \Component \TypeInfo \Type \ObjectType ;
25
- use Symfony \Component \TypeInfo \Type \WrappingTypeInterface ;
26
24
27
25
/**
28
26
* Field datatypes helpers.
@@ -108,13 +106,8 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
108
106
/** @var class-string|null $className */
109
107
$ className = null ;
110
108
111
- $ typeIsResourceClass = function (Type $ type ) use (&$ typeIsResourceClass , &$ className ): bool {
112
- return match (true ) {
113
- $ type instanceof WrappingTypeInterface => $ type ->wrappedTypeIsSatisfiedBy ($ typeIsResourceClass ),
114
- $ type instanceof CompositeTypeInterface => $ type ->composedTypesAreSatisfiedBy ($ typeIsResourceClass ),
115
- $ type instanceof ObjectType => $ this ->resourceClassResolver ->isResourceClass ($ className = $ type ->getClassName ()),
116
- default => false ,
117
- };
109
+ $ typeIsResourceClass = function (Type $ type ) use (&$ className ): bool {
110
+ return $ type instanceof ObjectType && $ this ->resourceClassResolver ->isResourceClass ($ className = $ type ->getClassName ());
118
111
};
119
112
120
113
if ($ type ->isSatisfiedBy ($ typeIsResourceClass )) {
@@ -123,16 +116,7 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s
123
116
return null === $ nestedPath ? $ nestedPath : "$ currentProperty. $ nestedPath " ;
124
117
}
125
118
126
- $ collectionValueTypeIsResourceClass = function (Type $ type ) use (&$ collectionValueTypeIsResourceClass , &$ className ): bool {
127
- return match (true ) {
128
- $ type instanceof CollectionType => $ type ->getCollectionValueType () instanceof ObjectType && $ this ->resourceClassResolver ->isResourceClass ($ className = $ type ->getCollectionValueType ()->getClassName ()),
129
- $ type instanceof WrappingTypeInterface => $ type ->wrappedTypeIsSatisfiedBy ($ collectionValueTypeIsResourceClass ),
130
- $ type instanceof CompositeTypeInterface => $ type ->composedTypesAreSatisfiedBy ($ collectionValueTypeIsResourceClass ),
131
- default => false ,
132
- };
133
- };
134
-
135
- if ($ type ->isSatisfiedBy ($ collectionValueTypeIsResourceClass )) {
119
+ if (TypeHelper::getCollectionValueType ($ type )?->isSatisfiedBy($ typeIsResourceClass )) {
136
120
$ nestedPath = $ this ->getNestedFieldPath ($ className , implode ('. ' , $ properties ));
137
121
138
122
return null === $ nestedPath ? $ currentProperty : "$ currentProperty. $ nestedPath " ;
0 commit comments