|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 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 Workbench\App\ApiResource; |
| 15 | + |
| 16 | +use ApiPlatform\Metadata\ApiResource; |
| 17 | +use ApiPlatform\Metadata\Get; |
| 18 | +use ApiPlatform\Metadata\Operation; |
| 19 | +use ApiPlatform\Metadata\Post; |
| 20 | + |
| 21 | +#[ApiResource( |
| 22 | + uriTemplate: '/issue7338_reproducers/{id}', |
| 23 | + operations: [ |
| 24 | + new Get( |
| 25 | + output: Issue7338Output::class, |
| 26 | + uriTemplate: '/issue7338_reproducers/{id}/output', |
| 27 | + provider: [self::class, 'provide'], |
| 28 | + normalizationContext: ['groups' => ['issue7338:output:read']] |
| 29 | + ), |
| 30 | + new Post( |
| 31 | + input: Issue7338Input::class, |
| 32 | + uriTemplate: '/issue7338_reproducers/input', |
| 33 | + processor: [self::class, 'process'], |
| 34 | + denormalizationContext: ['groups' => ['issue7338:input:write']], |
| 35 | + ), |
| 36 | + ] |
| 37 | +)] |
| 38 | +class Issue7338Reproducer |
| 39 | +{ |
| 40 | + public function __construct(public ?int $id = null, public ?string $title = null) |
| 41 | + { |
| 42 | + $this->id = $id; |
| 43 | + } |
| 44 | + |
| 45 | + public static function provide(Operation $operation, array $uriVariables = [], array $context = []) |
| 46 | + { |
| 47 | + return new Issue7338Output((int) $uriVariables['id'], 'Test Name', new \DateTimeImmutable()); |
| 48 | + } |
| 49 | + |
| 50 | + public static function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []) |
| 51 | + { |
| 52 | + \assert(null === $data->description); |
| 53 | + |
| 54 | + return new self(1, $data->title); |
| 55 | + } |
| 56 | +} |
0 commit comments