|
| 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\Issue7432; |
| 15 | + |
| 16 | +use ApiPlatform\Metadata\Operation; |
| 17 | +use ApiPlatform\Metadata\Patch; |
| 18 | + |
| 19 | +#[Patch( |
| 20 | + provider: [self::class, 'provide'], |
| 21 | + uriTemplate: '/original_data_with_listeners/{uuid}/verify', |
| 22 | + uriVariables: ['uuid'], |
| 23 | + input: UserVerifyInput::class, |
| 24 | + processor: [self::class, 'process'] |
| 25 | +)] |
| 26 | +class OriginalDataWithListeners |
| 27 | +{ |
| 28 | + public function __construct(public string $uuid, public ?string $code = null) |
| 29 | + { |
| 30 | + } |
| 31 | + |
| 32 | + public static function process($data, Operation $operation, array $uriVariables = [], array $context = []) |
| 33 | + { |
| 34 | + \assert($data instanceof UserVerifyInput); |
| 35 | + \assert($context['previous_data'] instanceof self); |
| 36 | + \assert($context['request']->attributes->get('data') instanceof UserVerifyInput); |
| 37 | + \assert($context['request']->attributes->get('previous_data') instanceof self); |
| 38 | + \assert($context['data'] instanceof UserVerifyInput); |
| 39 | + $context['previous_data']->code = $data->code; |
| 40 | + |
| 41 | + return $context['previous_data']; |
| 42 | + } |
| 43 | + |
| 44 | + public static function provide(Operation $operation, array $uriVariables = [], array $context = []) |
| 45 | + { |
| 46 | + return new self($uriVariables['uuid']); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +class UserVerifyInput |
| 51 | +{ |
| 52 | + public string $code; |
| 53 | +} |
0 commit comments