|
31 | 31 | use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface; |
32 | 32 | use ApiPlatform\GraphQl\Type\Definition\TypeInterface as GraphQlTypeInterface; |
33 | 33 | use ApiPlatform\Metadata\ApiResource; |
| 34 | +use ApiPlatform\Metadata\AsOperationMutator; |
34 | 35 | use ApiPlatform\Metadata\AsResourceMutator; |
35 | 36 | use ApiPlatform\Metadata\FilterInterface; |
| 37 | +use ApiPlatform\Metadata\OperationMutatorInterface; |
| 38 | +use ApiPlatform\Metadata\ResourceMutatorInterface; |
36 | 39 | use ApiPlatform\Metadata\UriVariableTransformerInterface; |
37 | 40 | use ApiPlatform\Metadata\UrlGeneratorInterface; |
38 | 41 | use ApiPlatform\OpenApi\Model\Tag; |
@@ -186,13 +189,29 @@ public function load(array $configs, ContainerBuilder $container): void |
186 | 189 | ->addTag('container.excluded', ['source' => 'by #[ApiResource] attribute']); |
187 | 190 | }); |
188 | 191 | $container->registerAttributeForAutoconfiguration(AsResourceMutator::class, |
189 | | - static function (ChildDefinition $definition, AsResourceMutator $attribute): void { |
| 192 | + static function (ChildDefinition $definition, AsResourceMutator $attribute, \ReflectionClass $reflector): void { |
| 193 | + if (!is_a($reflector->name, ResourceMutatorInterface::class, true)) { |
| 194 | + throw new RuntimeException(sprintf('Resource mutator "%s" should implement %s', $reflector->name, ResourceMutatorInterface::class)); |
| 195 | + } |
| 196 | + |
190 | 197 | $definition->addTag('api_platform.resource_mutator', [ |
191 | 198 | 'resourceClass' => $attribute->resourceClass, |
192 | 199 | ]); |
193 | 200 | }, |
194 | 201 | ); |
195 | 202 |
|
| 203 | + $container->registerAttributeForAutoconfiguration(AsOperationMutator::class, |
| 204 | + static function (ChildDefinition $definition, AsOperationMutator $attribute, \ReflectionClass $reflector): void { |
| 205 | + if (!is_a($reflector->name, OperationMutatorInterface::class, true)) { |
| 206 | + throw new RuntimeException(sprintf('Operation mutator "%s" should implement %s', $reflector->name, OperationMutatorInterface::class)); |
| 207 | + } |
| 208 | + |
| 209 | + $definition->addTag('api_platform.operation_mutator', [ |
| 210 | + 'operationName' => $attribute->operationName, |
| 211 | + ]); |
| 212 | + }, |
| 213 | + ); |
| 214 | + |
196 | 215 | if (!$container->has('api_platform.state.item_provider')) { |
197 | 216 | $container->setAlias('api_platform.state.item_provider', 'api_platform.state_provider.object'); |
198 | 217 | } |
|
0 commit comments