1 | <?php |
||
24 | final class Event |
||
25 | { |
||
26 | /** |
||
27 | * Event name |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $name; |
||
32 | |||
33 | /** |
||
34 | * Target state |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $targetState; |
||
39 | |||
40 | /** |
||
41 | * Error state |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $errorState; |
||
46 | |||
47 | /** |
||
48 | * Command executed when event is triggered |
||
49 | * |
||
50 | * @var callable |
||
51 | */ |
||
52 | private $command; |
||
53 | |||
54 | /** |
||
55 | * Additional attributes |
||
56 | * |
||
57 | * @var Attributes |
||
58 | */ |
||
59 | private $attributes; |
||
60 | |||
61 | /** |
||
62 | * Constructor |
||
63 | * |
||
64 | * @param string $name event name |
||
65 | * @param string $targetState state where subject will go when all commands were executed successfully |
||
66 | * @param string $errorState state where subject will go when command execution failed |
||
67 | * @param callable $command collection of commands |
||
68 | * @param array $attributes additional attributes. |
||
69 | * |
||
70 | * @throws InvalidArgumentException |
||
71 | */ |
||
72 | 33 | public function __construct( |
|
89 | |||
90 | /** |
||
91 | * Return event name |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | 18 | public function name(): string |
|
99 | |||
100 | /** |
||
101 | * Return name of success state |
||
102 | * Subject will go into this state when all commands execute properly |
||
103 | * |
||
104 | * @return null|string |
||
105 | */ |
||
106 | 10 | public function targetState() |
|
110 | |||
111 | /** |
||
112 | * Return error state name |
||
113 | * State where subject will go when something goes wrong |
||
114 | * |
||
115 | * @return null|string |
||
116 | */ |
||
117 | 4 | public function errorState() |
|
121 | |||
122 | /** |
||
123 | * Return attributes container |
||
124 | * |
||
125 | * @return Attributes |
||
126 | */ |
||
127 | 1 | public function attributes(): Attributes |
|
131 | |||
132 | /** |
||
133 | * Triggers event and return next state name or null if there is no state change |
||
134 | * |
||
135 | * @param Payload $payload |
||
136 | * |
||
137 | * @return null|string |
||
138 | */ |
||
139 | 12 | public function trigger(Payload $payload) |
|
147 | |||
148 | /** |
||
149 | * Return event string representation - its name |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 17 | public function __toString(): string |
|
157 | } |
||
158 |