1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Gember\EventSourcing\Resolver\UseCase; |
||
6 | |||
7 | use Gember\EventSourcing\Common\CreationPolicy; |
||
8 | use Gember\EventSourcing\Util\Serialization\Serializable; |
||
9 | |||
10 | /** |
||
11 | * @phpstan-type CommandHandlerDefinitionPayload array{ |
||
12 | * commandClassName: class-string, |
||
13 | * methodName: string, |
||
14 | * policy: string |
||
15 | * } |
||
16 | * |
||
17 | * @implements Serializable<CommandHandlerDefinitionPayload, CommandHandlerDefinition> |
||
18 | */ |
||
19 | final readonly class CommandHandlerDefinition implements Serializable |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
20 | { |
||
21 | /** |
||
22 | * @param class-string $commandClassName |
||
23 | */ |
||
24 | 11 | public function __construct( |
|
25 | public string $commandClassName, |
||
26 | public string $methodName, |
||
27 | public CreationPolicy $policy, |
||
28 | 11 | ) {} |
|
29 | |||
30 | 4 | public function toPayload(): array |
|
31 | { |
||
32 | 4 | return [ |
|
33 | 4 | 'commandClassName' => $this->commandClassName, |
|
34 | 4 | 'methodName' => $this->methodName, |
|
35 | 4 | 'policy' => $this->policy->value, |
|
36 | 4 | ]; |
|
37 | } |
||
38 | |||
39 | 4 | public static function fromPayload(array $payload): self |
|
40 | { |
||
41 | 4 | return new self( |
|
42 | 4 | $payload['commandClassName'], |
|
43 | 4 | $payload['methodName'], |
|
44 | 4 | CreationPolicy::from($payload['policy']), |
|
45 | 4 | ); |
|
46 | } |
||
47 | } |
||
48 |