1 | <?php |
||
16 | class ActionRouter { |
||
17 | |||
18 | /** @var AbstractAction */ |
||
19 | protected $action; |
||
20 | |||
21 | /** @var ActionRouter */ |
||
22 | protected static $instance = null; |
||
23 | |||
24 | /** @var int transition counter */ |
||
25 | protected $transitions = 0; |
||
26 | |||
27 | /** maximum loop */ |
||
28 | const MAX_TRANSITIONS = 5; |
||
29 | |||
30 | /** @var string[] the actions disabled in the configuration */ |
||
31 | protected $disabled; |
||
32 | |||
33 | /** |
||
34 | * ActionRouter constructor. Singleton, thus protected! |
||
35 | */ |
||
36 | protected function __construct() { |
||
43 | |||
44 | /** |
||
45 | * Get the singleton instance |
||
46 | * |
||
47 | * @param bool $reinit |
||
48 | * @return ActionRouter |
||
49 | */ |
||
50 | public static function getInstance($reinit = false) { |
||
56 | |||
57 | /** |
||
58 | * Sets up the correct action based on the $ACT global. Writes back the selected action to $ACT |
||
59 | */ |
||
60 | public function setupACT() { |
||
67 | |||
68 | /** |
||
69 | * Setup the given action |
||
70 | * |
||
71 | * Instantiates the right class, runs permission checks and pre-processing and |
||
72 | * sets $action |
||
73 | * |
||
74 | * @param string $actionname this is passed as a reference to $ACT, for plugin backward compatibility |
||
75 | * @triggers ACTION_ACT_PREPROCESS |
||
76 | */ |
||
77 | protected function setupAction(&$actionname) { |
||
118 | |||
119 | /** |
||
120 | * Transitions from one action to another |
||
121 | * |
||
122 | * Basically just calls setupAction() again but does some checks before. |
||
123 | * |
||
124 | * @param string $from current action name |
||
125 | * @param string $to new action name |
||
126 | * @param null|ActionException $e any previous exception that caused the transition |
||
127 | */ |
||
128 | protected function transitionAction($from, $to, $e = null) { |
||
144 | |||
145 | /** |
||
146 | * Aborts all processing with a message |
||
147 | * |
||
148 | * When a FataException instanc is passed, the code is treated as Status code |
||
149 | * |
||
150 | * @param \Exception|FatalException $e |
||
151 | * @throws FatalException during unit testing |
||
152 | */ |
||
153 | protected function handleFatalException(\Exception $e) { |
||
165 | |||
166 | /** |
||
167 | * Load the given action |
||
168 | * |
||
169 | * This translates the given name to a class name by uppercasing the first letter. |
||
170 | * Underscores translate to camelcase names. For actions with underscores, the different |
||
171 | * parts are removed beginning from the end until a matching class is found. The instatiated |
||
172 | * Action will always have the full original action set as Name |
||
173 | * |
||
174 | * Example: 'export_raw' -> ExportRaw then 'export' -> 'Export' |
||
175 | * |
||
176 | * @param $actionname |
||
177 | * @return AbstractAction |
||
178 | * @throws NoActionException |
||
179 | */ |
||
180 | public function loadAction($actionname) { |
||
194 | |||
195 | /** |
||
196 | * Execute all the checks to see if this action can be executed |
||
197 | * |
||
198 | * @param AbstractAction $action |
||
199 | * @throws ActionDisabledException |
||
200 | * @throws ActionException |
||
201 | */ |
||
202 | public function checkAction(AbstractAction $action) { |
||
222 | |||
223 | /** |
||
224 | * Returns the action handling the current request |
||
225 | * |
||
226 | * @return AbstractAction |
||
227 | */ |
||
228 | public function getAction() { |
||
231 | } |
||
232 |