|
19 | 19 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; |
20 | 20 | use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; |
21 | 21 | use ApiPlatform\Metadata\ResourceClassResolverInterface; |
22 | | -use Symfony\Component\PropertyInfo\PropertyInfoExtractor; |
23 | | -use Symfony\Component\PropertyInfo\Type as LegacyType; |
24 | 22 | use Symfony\Component\Serializer\NameConverter\NameConverterInterface; |
25 | 23 | use Symfony\Component\TypeInfo\Type; |
26 | 24 | use Symfony\Component\TypeInfo\Type\CollectionType; |
@@ -81,10 +79,6 @@ protected function hasProperty(string $resourceClass, string $property): bool |
81 | 79 | */ |
82 | 80 | protected function getMetadata(string $resourceClass, string $property): array |
83 | 81 | { |
84 | | - if (!method_exists(PropertyInfoExtractor::class, 'getType')) { |
85 | | - return $this->getLegacyMetadata($resourceClass, $property); |
86 | | - } |
87 | | - |
88 | 82 | $noop = [null, null, null, null]; |
89 | 83 |
|
90 | 84 | if (!$this->hasProperty($resourceClass, $property)) { |
@@ -176,95 +170,4 @@ protected function getMetadata(string $resourceClass, string $property): array |
176 | 170 |
|
177 | 171 | return [$type, $hasAssociation, $currentResourceClass, $currentProperty]; |
178 | 172 | } |
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 | | - } |
270 | 173 | } |
0 commit comments