1 | <?php |
||
16 | class ActionRouter { |
||
17 | |||
18 | /** @var AbstractAction */ |
||
19 | protected $action; |
||
20 | |||
21 | /** @var ActionRouter */ |
||
22 | protected static $instance; |
||
23 | |||
24 | /** @var int transition counter */ |
||
25 | protected $transitions = 0; |
||
26 | |||
27 | /** maximum loop */ |
||
28 | const MAX_TRANSITIONS = 5; |
||
29 | |||
30 | /** |
||
31 | * ActionRouter constructor. Singleton, thus protected! |
||
32 | * |
||
33 | * Sets up the correct action based on the $ACT global. Writes back |
||
34 | * the selected action to $ACT |
||
35 | */ |
||
36 | protected function __construct() { |
||
42 | |||
43 | /** |
||
44 | * Get the singleton instance |
||
45 | * |
||
46 | * @param bool $reinit |
||
47 | * @return ActionRouter |
||
48 | */ |
||
49 | public static function getInstance($reinit = false) { |
||
55 | |||
56 | /** |
||
57 | * Setup the given action |
||
58 | * |
||
59 | * Instantiates the right class, runs permission checks and pre-processing and |
||
60 | * sets $action |
||
61 | * |
||
62 | * @param string $actionname |
||
63 | * @triggers ACTION_ACT_PREPROCESS |
||
64 | */ |
||
65 | protected function setupAction($actionname) { |
||
106 | |||
107 | /** |
||
108 | * Transitions from one action to another |
||
109 | * |
||
110 | * Basically just calls setupAction() again but does some checks before. Also triggers |
||
111 | * redirects for POST to show transitions |
||
112 | * |
||
113 | * @param string $from current action name |
||
114 | * @param string $to new action name |
||
115 | * @param null|ActionException $e any previous exception that caused the transition |
||
116 | */ |
||
117 | protected function transitionAction($from, $to, $e = null) { |
||
141 | |||
142 | /** |
||
143 | * Check that the given minimum permissions are reached |
||
144 | * |
||
145 | * @param int $permneed |
||
146 | * @throws ActionException |
||
147 | */ |
||
148 | protected function ensureMinimumPermission($permneed) { |
||
154 | |||
155 | /** |
||
156 | * Aborts all processing with a message |
||
157 | * |
||
158 | * When a FataException instanc is passed, the code is treated as Status code |
||
159 | * |
||
160 | * @param \Exception|FatalException $e |
||
161 | */ |
||
162 | protected function handleFatalException(\Exception $e) { |
||
171 | |||
172 | /** |
||
173 | * Load the given action |
||
174 | * |
||
175 | * This translates the given name to a class name by uppercasing the first letter. |
||
176 | * Underscores translate to camelcase names. For actions with underscores, the different |
||
177 | * parts are removed beginning from the end until a matching class is found. The instatiated |
||
178 | * Action will always have the full original action set as Name |
||
179 | * |
||
180 | * Example: 'export_raw' -> ExportRaw then 'export' -> 'Export' |
||
181 | * |
||
182 | * @param $actionname |
||
183 | * @return AbstractAction |
||
184 | * @throws NoActionException |
||
185 | */ |
||
186 | protected function loadAction($actionname) { |
||
200 | |||
201 | /** |
||
202 | * Returns the action handling the current request |
||
203 | * |
||
204 | * @return AbstractAction |
||
205 | */ |
||
206 | public function getAction() { |
||
209 | } |
||
210 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.