|
18 | 18 | use ApiPlatform\Api\UrlGeneratorInterface;
|
19 | 19 | use ApiPlatform\JsonLd\ContextBuilderInterface;
|
20 | 20 | use ApiPlatform\JsonLd\Serializer\JsonLdContextTrait;
|
21 |
| -use ApiPlatform\Metadata\CollectionOperationInterface; |
22 | 21 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
|
23 | 22 | use ApiPlatform\Serializer\ContextTrait;
|
24 | 23 | use ApiPlatform\State\Pagination\PaginatorInterface;
|
@@ -50,6 +49,10 @@ final class CollectionNormalizer implements NormalizerInterface, NormalizerAware
|
50 | 49 | public function __construct(private readonly ContextBuilderInterface $contextBuilder, private readonly ResourceClassResolverInterface $resourceClassResolver, private readonly IriConverterInterface $iriConverter, private readonly ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, array $defaultContext = [])
|
51 | 50 | {
|
52 | 51 | $this->defaultContext = array_merge($this->defaultContext, $defaultContext);
|
| 52 | + |
| 53 | + if ($this->resourceMetadataCollectionFactory) { |
| 54 | + trigger_deprecation('api-platform/core', '3.0', sprintf('Injecting "%s" within "%s" is not needed anymore and this dependency will be removed in 4.0.', ResourceMetadataCollectionFactoryInterface::class, self::class)); |
| 55 | + } |
53 | 56 | }
|
54 | 57 |
|
55 | 58 | /**
|
@@ -80,11 +83,11 @@ public function normalize(mixed $object, string $format = null, array $context =
|
80 | 83 | $data['hydra:member'] = [];
|
81 | 84 | $iriOnly = $context[self::IRI_ONLY] ?? $this->defaultContext[self::IRI_ONLY];
|
82 | 85 |
|
83 |
| - if ($this->resourceMetadataCollectionFactory && ($operation = $context['operation'] ?? null) instanceof CollectionOperationInterface && method_exists($operation, 'getItemUriTemplate') && ($itemUriTemplate = $operation->getItemUriTemplate())) { |
84 |
| - $context['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation($operation->getItemUriTemplate()); |
85 |
| - } else { |
86 |
| - unset($context['operation']); |
| 86 | + if (($operation = $context['operation'] ?? null) && method_exists($operation, 'getItemUriTemplate')) { |
| 87 | + $context['item_uri_template'] = $operation->getItemUriTemplate(); |
87 | 88 | }
|
| 89 | + |
| 90 | + unset($context['operation']); |
88 | 91 | unset($context['operation_name'], $context['uri_variables']);
|
89 | 92 |
|
90 | 93 | foreach ($object as $obj) {
|
|
0 commit comments