|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6673; |
| 15 | + |
| 16 | +use ApiPlatform\Metadata\GetCollection; |
| 17 | +use ApiPlatform\Metadata\Operation; |
| 18 | +use ApiPlatform\Metadata\Parameter; |
| 19 | +use ApiPlatform\Metadata\QueryParameter; |
| 20 | + |
| 21 | +#[GetCollection( |
| 22 | + uriTemplate: 'issue6673_multiple_parameter_provider', |
| 23 | + shortName: 'multiple_parameter_provider', |
| 24 | + outputFormats: ['json'], |
| 25 | + parameters: [ |
| 26 | + 'a' => new QueryParameter( |
| 27 | + provider: [self::class, 'parameterOneProvider'], |
| 28 | + ), |
| 29 | + 'b' => new QueryParameter( |
| 30 | + provider: [self::class, 'parameterTwoProvider'], |
| 31 | + ), |
| 32 | + ], |
| 33 | + provider: [self::class, 'provide'] |
| 34 | +)] |
| 35 | +final class MutlipleParameterProvider |
| 36 | +{ |
| 37 | + public function __construct(public readonly string $id) |
| 38 | + { |
| 39 | + } |
| 40 | + |
| 41 | + public static function provide(Operation $operation): ?array |
| 42 | + { |
| 43 | + return $operation->getNormalizationContext(); |
| 44 | + } |
| 45 | + |
| 46 | + public static function parameterOneProvider(Parameter $parameter, array $parameters = [], array $context = []): ?Operation |
| 47 | + { |
| 48 | + $operation = $context['operation']; |
| 49 | + $context = $operation->getNormalizationContext() ?? []; |
| 50 | + $context['a'] = $parameter->getValue(); |
| 51 | + |
| 52 | + return $operation->withNormalizationContext($context); |
| 53 | + } |
| 54 | + |
| 55 | + public static function parameterTwoProvider(Parameter $parameter, array $parameters = [], array $context = []): ?Operation |
| 56 | + { |
| 57 | + $operation = $context['operation']; |
| 58 | + $context = $operation->getNormalizationContext() ?? []; |
| 59 | + $context['b'] = $parameter->getValue(); |
| 60 | + |
| 61 | + return $operation->withNormalizationContext($context); |
| 62 | + } |
| 63 | +} |
0 commit comments