public function executeAction($handler, $vars = [], $fire_events = true)
{
$logger = $this->container['logger'];
$executable = null;
if (is_callable($handler)) {
$executable = $handler;
} else {
list($controller_name, $action_name) = $this->app->getControllerByHandler($handler);
$controller = $this->app->createController($controller_name);
$executable = [$controller, $action_name];
}
if ($fire_events) {
$event = new ExecuteActionEvent($this->app, $executable, $vars);
$this->event_dispatcher->dispatch(DietcubeEvents::EXECUTE_ACTION, $event);
$executable = $event->getExecutable();
$vars = $event->getVars();
}
// Executable may changed by custom event so parse info again.
if ($executable instanceof \Closure) {
$controller_name = 'function()';
$action_name = '-';
} else {
$controller_name = get_class($executable[0]);
$action_name = $executable[1];
if (!is_callable($executable)) {
// anon function is always callable so when the handler is anon function it never come here.
$logger->error('Action not dispatchable.', ['controller' => $controller_name, 'action_name' => $action_name]);
throw new DCException("'{$controller_name}::{$action_name}' is not a valid action.");
}
}
$logger->debug('Exceute action.', ['controller' => $controller_name, 'action' => $action_name, 'vars' => $vars]);
return call_user_func_array($executable, $vars);
}