registry = $registry; } /** * @param ActionSystem $pre_action * @return void */ public function addPreAction(\Phacil\Framework\ActionSystem $pre_action) { $this->pre_action[] = $pre_action; } /** * @param Action $action * @param Action $error * @return void */ public function dispatch(\Phacil\Framework\Action $action, \Phacil\Framework\Action $error) { $this->error = $error; foreach ($this->pre_action as $pre_action) { $result = $this->execute($pre_action); if ($result) { $action = $result; break; } } while ($action) { $action = $this->execute($action); } } private function execute($action) { $file = $action->getFile(); $class = $action->getClass(); $method = $action->getMethod(); $args = $action->getArgs(); $action = ''; if (file_exists($file)) { require_once($file); $controller = new $class($this->registry); if (is_callable(array($controller, $method))) { $action = call_user_func_array(array($controller, $method), $args); } else { $action = $this->error; $this->error = ''; } } else { $action = $this->error; $this->error = ''; } return $action; } }