1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* cqrs (https://github.com/phpgears/cqrs). |
5
|
|
|
* CQRS base. |
6
|
|
|
* |
7
|
|
|
* @license MIT |
8
|
|
|
* @link https://github.com/phpgears/cqrs |
9
|
|
|
* @author Julián Gutiérrez <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Gears\CQRS; |
15
|
|
|
|
16
|
|
|
use Gears\CQRS\Exception\QueryException; |
17
|
|
|
use Gears\DTO\ScalarPayloadBehaviour; |
18
|
|
|
use Gears\Immutability\ImmutabilityBehaviour; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract immutable query. |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractQuery implements Query |
24
|
|
|
{ |
25
|
|
|
use ImmutabilityBehaviour, ScalarPayloadBehaviour { |
26
|
|
|
ScalarPayloadBehaviour::__call insteadof ImmutabilityBehaviour; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* AbstractQuery constructor. |
31
|
|
|
* |
32
|
|
|
* @param mixed[] $parameters |
33
|
|
|
*/ |
34
|
|
|
final protected function __construct(array $parameters) |
35
|
|
|
{ |
36
|
|
|
$this->assertImmutable(); |
37
|
|
|
|
38
|
|
|
$this->setPayload($parameters); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getQueryType(): string |
45
|
|
|
{ |
46
|
|
|
return static::class; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string[] |
51
|
|
|
*/ |
52
|
|
|
final public function __sleep(): array |
53
|
|
|
{ |
54
|
|
|
throw new QueryException(\sprintf('Query "%s" cannot be serialized.', static::class)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
final public function __wakeup(): void |
58
|
|
|
{ |
59
|
|
|
throw new QueryException(\sprintf('Query "%s" cannot be unserialized.', static::class)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return array<string, mixed> |
64
|
|
|
*/ |
65
|
|
|
final public function __serialize(): array |
66
|
|
|
{ |
67
|
|
|
throw new QueryException(\sprintf('Query "%s" cannot be serialized.', static::class)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param array<string, mixed> $data |
72
|
|
|
* |
73
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
74
|
|
|
*/ |
75
|
|
|
final public function __unserialize(array $data): void |
76
|
|
|
{ |
77
|
|
|
throw new QueryException(\sprintf('Query "%s" cannot be unserialized.', static::class)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
* |
83
|
|
|
* @return string[] |
84
|
|
|
*/ |
85
|
|
|
final protected function getAllowedInterfaces(): array |
86
|
|
|
{ |
87
|
|
|
return [Query::class]; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|