/** * Execute an action by triggering a method in the derived class. * * @param string $action The action to execute * @param CommandContext $context A command context object * @throws ControllerException If the action method doesn't exist * @return mixed|false The value returned by the called method, false in error case. */ public function execute($action, CommandContext $context) { $action = strtolower($action); //Update the context $context->action = $action; $context->setSubject($this); //Find the mapped action if (isset($this->_action_map[$action])) { $command = $this->_action_map[$action]; } else { $command = $action; } //Execute the action if ($this->getCommandChain()->run('before.' . $command, $context) !== false) { $method = '_action' . ucfirst($command); if (!method_exists($this, $method)) { if (isset($this->_mixed_methods[$command])) { $context->result = $this->_mixed_methods[$command]->execute('action.' . $command, $context); } else { throw new ControllerExceptionNotImplemented("Can't execute '{$command}', method: '{$method}' does not exist"); } } else { $context->result = $this->{$method}($context); } $this->getCommandChain()->run('after.' . $command, $context); } return $context->result; }