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 | * @param object $subject |
||
80 | * @param ProcessInterface $process |
||
81 | * @param string $stateName |
||
82 | * @param TransitionSelectorInterface $transitonSelector |
||
83 | * @param MutexInterface $mutex |
||
84 | */ |
||
85 | 9 | public function __construct( |
|
111 | |||
112 | /** |
||
113 | * @return ProcessInterface |
||
114 | */ |
||
115 | public function getProcess() |
||
119 | |||
120 | /** |
||
121 | * @see MetaborStd\Statemachine.StatemachineInterface::getCurrentState() |
||
122 | */ |
||
123 | 6 | public function getCurrentState() |
|
127 | |||
128 | /** |
||
129 | * @return StateInterface |
||
130 | */ |
||
131 | 1 | public function getLastState() |
|
135 | |||
136 | /** |
||
137 | * @param \ArrayAccess $context |
||
138 | * @param EventInterface $event |
||
139 | */ |
||
140 | 3 | protected function doCheckTransitions(\ArrayAccess $context, EventInterface $event = null) |
|
169 | |||
170 | /** |
||
171 | * @return \MetaborStd\Statemachine\TransitionInterface |
||
172 | */ |
||
173 | 1 | public function getSelectedTransition() |
|
177 | |||
178 | /** |
||
179 | * is called after dispatcher was executed. |
||
180 | */ |
||
181 | 3 | public function onDispatcherReady() |
|
193 | |||
194 | /** |
||
195 | * @param DispatcherInterface $dispatcher |
||
196 | * @param string $name |
||
197 | * @param \ArrayAccess $context |
||
198 | * |
||
199 | * @throws \RuntimeException |
||
200 | */ |
||
201 | 4 | public function dispatchEvent(DispatcherInterface $dispatcher, $name, \ArrayAccess $context = null) |
|
223 | |||
224 | /** |
||
225 | * @see MetaborStd\Statemachine.StatemachineInterface::triggerEvent() |
||
226 | */ |
||
227 | 4 | public function triggerEvent($name, \ArrayAccess $context = null) |
|
233 | |||
234 | /** |
||
235 | * @see MetaborStd\Statemachine.StatemachineInterface::checkTransitions() |
||
236 | */ |
||
237 | 3 | public function checkTransitions() |
|
244 | |||
245 | /** |
||
246 | * @see \MetaborStd\Statemachine\StatemachineInterface::getSubject() |
||
247 | */ |
||
248 | 6 | public function getSubject() |
|
252 | |||
253 | /** |
||
254 | * @return \ArrayAccess |
||
255 | */ |
||
256 | public function getCurrentContext() |
||
260 | |||
261 | /** |
||
262 | * @throws LockCanNotBeAcquiredException |
||
263 | */ |
||
264 | 3 | protected function acquireLockOrThrowException() |
|
270 | |||
271 | /** |
||
272 | * Use this function if you want to aquire lock before calling triggerEvent or checkTransitions. |
||
273 | * Lock is aquired automatically when calling dispatchEvent or checkTransitions. |
||
274 | * |
||
275 | * @return bool |
||
276 | */ |
||
277 | 3 | public function acquireLock() |
|
285 | } |
||
286 |
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: