1 | <?php |
||
17 | class Utils { |
||
18 | const STATE_CONCATENATOR = '_to_'; |
||
19 | |||
20 | /** |
||
21 | * gets the transition name by two state names, using the default convention |
||
22 | * for a transition name (which is concatenating state-from to state-to with |
||
23 | * '_to_') |
||
24 | * |
||
25 | * @param string $from |
||
26 | * the state from which the transition is made |
||
27 | * @param string $to |
||
28 | * the state to which the transition will be made |
||
29 | * @return string <state_from>_to_<state_to> |
||
30 | */ |
||
31 | 64 | public static function getTransitionName($from, $to) |
|
35 | |||
36 | /** |
||
37 | * returns the associated Command for the entry/exit/transition action on a |
||
38 | * State or a Transition. |
||
39 | * the Command will be configured with the 'reference' of the stateful |
||
40 | * object |
||
41 | * |
||
42 | * @param string $command_name |
||
43 | * entry~,exit~ or transition command name. |
||
44 | * multiple commands can be split by a ',' in which case a |
||
45 | * composite command will be returned. |
||
46 | * @param Context $context |
||
47 | * to be able to get the entity |
||
48 | * @return ICommand |
||
49 | * @throws Exception |
||
50 | */ |
||
51 | 39 | public static function getCommand($command_name, Context $context) |
|
88 | |||
89 | /** |
||
90 | * Always returns an izzum exception (converts a non-izzum exception to an |
||
91 | * izzum exception). |
||
92 | * optionally throws it. |
||
93 | * |
||
94 | * @param \Exception $e |
||
95 | * @param int $code |
||
96 | * @return Exception |
||
97 | * @throws Exception |
||
98 | */ |
||
99 | 4 | public static function wrapToStateMachineException(\Exception $e, $code, $throw = false) |
|
110 | |||
111 | /** |
||
112 | * get all states that match a possible regex state from the set of states |
||
113 | * provided |
||
114 | * |
||
115 | * @param State $regex |
||
116 | * a possible regex state. |
||
117 | * @param State[] $targets |
||
118 | * all target State instances that we check the regex against. |
||
119 | * @return State[] an array of State instances from the $targets State |
||
120 | * instances that matched the (negated) regex, or the $regex State if it was |
||
121 | * not a regex State after all. |
||
122 | * @link https://php.net/manual/en/function.preg-match.php |
||
123 | * @link http://regexr.com/ for trying out regular expressions |
||
124 | */ |
||
125 | 41 | public static function getAllRegexMatchingStates(State $regex, $targets) |
|
140 | |||
141 | /** |
||
142 | * does an input regex state match a target states' name? |
||
143 | * |
||
144 | * @param State $regex |
||
145 | * the regex state |
||
146 | * @param State $target |
||
147 | * the state to match the regular expression to |
||
148 | * @return boolean |
||
149 | * @link https://php.net/manual/en/function.preg-match.php |
||
150 | * @link http://regexr.com/ for trying out regular expressions |
||
151 | */ |
||
152 | 20 | public static function matchesRegex(State $regex, State $target) |
|
165 | } |