1 | <?php |
||
26 | class Statemachine extends Subject implements StatemachineInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var object |
||
30 | */ |
||
31 | private $subject; |
||
32 | |||
33 | /** |
||
34 | * @var StateInterface |
||
35 | */ |
||
36 | private $currentState; |
||
37 | |||
38 | /** |
||
39 | * @var StateInterface |
||
40 | */ |
||
41 | private $lastState; |
||
42 | |||
43 | /** |
||
44 | * @var DispatcherInterface |
||
45 | */ |
||
46 | private $dispatcher; |
||
47 | |||
48 | /** |
||
49 | * @var EventInterface |
||
50 | */ |
||
51 | private $currentEvent; |
||
52 | |||
53 | /** |
||
54 | * @var \ArrayAccess |
||
55 | */ |
||
56 | private $currentContext; |
||
57 | |||
58 | /** |
||
59 | * @var TransitionSelectorInterface |
||
60 | */ |
||
61 | private $transitonSelector; |
||
62 | |||
63 | /** |
||
64 | * @var TransitionInterface |
||
65 | */ |
||
66 | private $selectedTransition; |
||
67 | |||
68 | /** |
||
69 | * @var ProcessInterface |
||
70 | */ |
||
71 | private $process; |
||
72 | |||
73 | /** |
||
74 | * @var MutexInterface |
||
75 | */ |
||
76 | private $mutex; |
||
77 | |||
78 | /** |
||
79 | * @var bool |
||
80 | */ |
||
81 | private $autoreleaseLock = true; |
||
82 | |||
83 | /** |
||
84 | * @param object $subject |
||
85 | * @param ProcessInterface $process |
||
86 | * @param string $stateName |
||
87 | * @param TransitionSelectorInterface $transitonSelector |
||
88 | * @param MutexInterface $mutex |
||
89 | */ |
||
90 | public function __construct( |
||
116 | |||
117 | /** |
||
118 | * @return ProcessInterface |
||
119 | */ |
||
120 | public function getProcess() |
||
124 | |||
125 | /** |
||
126 | * @see MetaborStd\Statemachine.StatemachineInterface::getCurrentState() |
||
127 | */ |
||
128 | public function getCurrentState() |
||
132 | |||
133 | /** |
||
134 | * @return StateInterface |
||
135 | */ |
||
136 | public function getLastState() |
||
140 | |||
141 | /** |
||
142 | * @param \ArrayAccess $context |
||
143 | * @param EventInterface $event |
||
144 | */ |
||
145 | protected function doCheckTransitions(\ArrayAccess $context, EventInterface $event = null) |
||
177 | |||
178 | /** |
||
179 | * @return \MetaborStd\Statemachine\TransitionInterface |
||
180 | */ |
||
181 | public function getSelectedTransition() |
||
185 | |||
186 | /** |
||
187 | * is called after dispatcher was executed. |
||
188 | */ |
||
189 | public function onDispatcherReady() |
||
203 | |||
204 | /** |
||
205 | * @param DispatcherInterface $dispatcher |
||
206 | * @param string $name |
||
207 | * @param \ArrayAccess $context |
||
208 | * |
||
209 | * @throws \RuntimeException |
||
210 | */ |
||
211 | public function dispatchEvent(DispatcherInterface $dispatcher, $name, \ArrayAccess $context = null) |
||
233 | |||
234 | /** |
||
235 | * @param string $name |
||
236 | * @param \ArrayAccess|null $context |
||
237 | */ |
||
238 | public function triggerEvent($name, \ArrayAccess $context = null) |
||
244 | |||
245 | /** |
||
246 | * @param \ArrayAccess|null $context |
||
247 | */ |
||
248 | public function checkTransitions(\ArrayAccess $context = null) |
||
259 | |||
260 | /** |
||
261 | * @see \MetaborStd\Statemachine\StatemachineInterface::getSubject() |
||
262 | */ |
||
263 | public function getSubject() |
||
267 | |||
268 | /** |
||
269 | * @return \ArrayAccess |
||
270 | */ |
||
271 | public function getCurrentContext() |
||
275 | |||
276 | /** |
||
277 | * @throws LockCanNotBeAcquiredException |
||
278 | */ |
||
279 | protected function acquireLockOrThrowException() |
||
285 | |||
286 | /** |
||
287 | * @return bool |
||
288 | */ |
||
289 | public function isAutoreleaseLock() |
||
293 | |||
294 | /** |
||
295 | * @param bool $autoreleaseLock |
||
296 | */ |
||
297 | public function setAutoreleaseLock($autoreleaseLock) |
||
301 | |||
302 | /** |
||
303 | * Use this function if you want to aquire lock before calling triggerEvent or checkTransitions. |
||
304 | * Lock is aquired automatically when calling dispatchEvent or checkTransitions. |
||
305 | * |
||
306 | * @return bool |
||
307 | */ |
||
308 | public function acquireLock() |
||
316 | |||
317 | /** |
||
318 | * Manuall release of the lock. |
||
319 | * Can be used for example if you disable autorelase of locks |
||
320 | */ |
||
321 | public function releaseLock() |
||
325 | |||
326 | /** |
||
327 | * @return bool |
||
328 | */ |
||
329 | public function isLockAcquired() |
||
333 | } |
||
334 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: