* @package oat\tao\model\routing */ class CliController implements ServiceManagerAwareInterface { use ServiceManagerAwareTrait; /** * @param string $actionIdentifier fully qualified action class name * @param array $params Params to be passed to action's __invoke method * @return Report */ public function runAction($actionIdentifier, array $params = []) { try { $actionService = $this->getServiceLocator()->get(ActionService::SERVICE_ID); $action = $actionService->resolve($actionIdentifier); } catch (ResolutionException $e) { return new Report(Report::TYPE_ERROR, $e->getMessage()); } $this->propagate($action); $this->getServiceLocator()->get(ArgumentService::SERVICE_ID)->load($action, $params); try { $report = call_user_func($action, $params); if (empty($report)) { $shortName = (new \ReflectionClass($action))->getName(); $report = new \common_report_Report(\common_report_Report::TYPE_INFO, "Action '${shortName}' ended gracefully with no report returned."); } } catch (\Exception $e) { $report = new Report(Report::TYPE_ERROR, __('An exception occured while running "%s"', $actionIdentifier)); $message = $e->getMessage(); $previous = $e->getPrevious(); // Get the full stack trace of the exception while ($previous) { $message .= PHP_EOL . "caused by : " . PHP_EOL . $previous->getMessage(); $previous = $previous->getPrevious(); } $report->add(new Report(Report::TYPE_ERROR, $message)); } return $report; } }