private static function getActionResult($controller, $action) { $controller = $controller . '_controller'; if (!class_exists($controller)) { throw new WebException($controller, $action, "Can't find controller - [{$controller}]"); } if (!method_exists($controller, $action)) { throw new WebException($controller, $action, "Can't find action [{$action}] in [{$controller}]"); } /** * @var Controller $controller */ $controller = DI::get($controller); $ref = new \ReflectionClass($controller); $controller->attributes = AttributeCollection::create($ref->getDocComment()); $controller->req = DI::get(Request::class); $pageLoadResult = $controller->onPageLoad(); if (isset($pageLoadResult)) { return $pageLoadResult; } if (!$controller->isEnded) { $actionInfo = new ActionInfo($controller, $action); try { $actionResult = $actionInfo->invoke($controller->req->params(), $controller->req->posts()); return $actionResult; } catch (\Exception $ex) { if ($controller instanceof OutputStatusException || $actionInfo->getIfOutputStatusException() || $controller->attributes->exists(OutputStatusExceptionAttribute::class)) { $status = $controller->status($ex->getMessage(), $ex->getCode()); return $status; } throw new WebException($controller, $action, $ex->getMessage(), $ex); } } return null; }
private function initializeAttributes() { $this->attributes = AttributeCollection::create($this->docComment); }