|
20 | 20 | use ApiPlatform\Core\Exception\InvalidArgumentException;
|
21 | 21 | use ApiPlatform\Core\Exception\RuntimeException;
|
22 | 22 | use ApiPlatform\Core\Util\ResourceClassInfoTrait;
|
| 23 | +use ApiPlatform\Exception\OperationNotFoundException; |
23 | 24 | use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface as GraphQlMercureSubscriptionIriGeneratorInterface;
|
24 | 25 | use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface as GraphQlSubscriptionManagerInterface;
|
25 | 26 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
|
@@ -72,7 +73,7 @@ final class PublishMercureUpdatesListener
|
72 | 73 | * @param array<string, string[]|string> $formats
|
73 | 74 | * @param HubRegistry|callable $hubRegistry
|
74 | 75 | */
|
75 |
| - public function __construct(ResourceClassResolverInterface $resourceClassResolver, IriConverterInterface $iriConverter, $resourceMetadataFactory, SerializerInterface $serializer, array $formats, MessageBusInterface $messageBus = null, $hubRegistry = null, ?GraphQlSubscriptionManagerInterface $graphQlSubscriptionManager = null, ?GraphQlMercureSubscriptionIriGeneratorInterface $graphQlMercureSubscriptionIriGenerator = null, ExpressionLanguage $expressionLanguage = null) |
| 76 | + public function __construct(ResourceClassResolverInterface $resourceClassResolver, IriConverterInterface $iriConverter, ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, SerializerInterface $serializer, array $formats, MessageBusInterface $messageBus = null, $hubRegistry = null, ?GraphQlSubscriptionManagerInterface $graphQlSubscriptionManager = null, ?GraphQlMercureSubscriptionIriGeneratorInterface $graphQlMercureSubscriptionIriGenerator = null, ExpressionLanguage $expressionLanguage = null) |
76 | 77 | {
|
77 | 78 | if (null === $messageBus && null === $hubRegistry) {
|
78 | 79 | throw new InvalidArgumentException('A message bus or a hub registry must be provided.');
|
@@ -172,7 +173,11 @@ private function storeObjectToPublish($object, string $property): void
|
172 | 173 | return;
|
173 | 174 | }
|
174 | 175 |
|
175 |
| - $options = $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false); |
| 176 | + try { |
| 177 | + $options = $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getMercure() ?? false; |
| 178 | + } catch (OperationNotFoundException $e) { |
| 179 | + return; |
| 180 | + } |
176 | 181 |
|
177 | 182 | if (\is_string($options)) {
|
178 | 183 | if (null === $this->expressionLanguage) {
|
@@ -264,12 +269,7 @@ private function publishUpdate($object, array $options, string $type): void
|
264 | 269 | $data = json_encode(['@id' => $object->id]);
|
265 | 270 | } else {
|
266 | 271 | $resourceClass = $this->getObjectClass($object);
|
267 |
| - if ($this->resourceMetadataFactory instanceof ResourceMetadataCollectionFactoryInterface) { |
268 |
| - $context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getNormalizationContext(); |
269 |
| - } else { |
270 |
| - // TODO: remove in 3.0 |
271 |
| - $context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getAttribute('normalization_context', []); |
272 |
| - } |
| 272 | + $context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getNormalizationContext(); |
273 | 273 |
|
274 | 274 | $iri = $options['topics'] ?? $this->iriConverter->getIriFromItem($object, null, UrlGeneratorInterface::ABS_URL);
|
275 | 275 | $data = $options['data'] ?? $this->serializer->serialize($object, key($this->formats), $context);
|
|
0 commit comments