/** * Execute an action by triggering a method in the derived class. * * @param string $action The action to execute * @param KControllerContextInterface $context A command context object * @throws Exception * @throws BadMethodCallException * @return mixed|bool The value returned by the called method, false in error case. */ public function execute($action, KControllerContextInterface $context) { $action = strtolower($action); //Set the context subject $context_subject = $context->getSubject(); $context->setSubject($this); //Set the context action $context_action = $context->getAction(); $context->setAction($action); //Execute the action if ($this->invokeCommand('before.' . $action, $context) !== false) { $method = '_action' . ucfirst($action); if (!method_exists($this, $method)) { if (isset($this->_mixed_methods[$action])) { $context->setName('action.' . $action); $context->result = $this->_mixed_methods[$action]->execute($context, $this->getCommandChain()); } else { throw new KControllerExceptionActionNotImplemented("Can't execute '{$action}', method: '{$method}' does not exist"); } } else { $context->result = $this->{$method}($context); } $this->invokeCommand('after.' . $action, $context); } //Reset the context $context->setSubject($context_subject); $context->setAction($context_action); return $context->result; }