public function execute() { if (Settings::get(Settings::DEBUG, false)) { if (isset($_GET['__clearcache'])) { //Clear cache Dir::emptyDir(CACHEDIR, true); } if (isset($_GET['__clearview'])) { //Clear cache Dir::emptyDir(Dir::concat(CACHEDIR, 'view'), true); } if (isset($_GET['__clearjs'])) { //Clear cache Dir::emptyDir(Dir::concat(CACHEDIR, 'js'), true); } if (isset($_GET['__clearcss'])) { //Clear cache Dir::emptyDir(Dir::concat(CACHEDIR, 'css'), true); } } try { if (!String::isAlphaNum($this->controller)) { header("HTTP/1.0 404 Invalid url"); throw new HttpNotFoundException(T('Invalid controller: %s', $this->controller)); } if (!String::isAlphaNum($this->action)) { header("HTTP/1.1 404 Invalid url"); throw new HttpNotFoundException(T('Invalid action: %s', $this->action)); } $ctrlClass = ucfirst($this->controller) . 'Controller'; $appViewFile = 'application'; $viewFile = $this->getViewFile(); if (!class_exists($ctrlClass)) { $ctrlFile = Dir::normalize(BASEDIR) . 'controller/' . $ctrlClass . '.php'; if (!File::exists($ctrlFile)) { header("HTTP/1.1 404 Controller not found"); throw new HttpNotFoundException(T('Controller not found: %s', $ctrlFile)); } require_once $ctrlFile; } if (!class_exists($ctrlClass)) { header("HTTP/1.1 404 Controller not Found"); throw new HttpNotFoundException(T('Controller not found: %s', $ctrlClass)); } $ctrl = new $ctrlClass(); $this->controllerInstance = $ctrl; if (!method_exists($ctrl, $this->action)) { header("HTTP/1.1 404 Action not Found"); throw new HttpNotFoundException(T('Action not found: %s::%s', $ctrlClass, $this->action)); } $action = $this->action; if (!$ctrl->getSkipView()) { try { $view = new View($viewFile); } catch (Exception $e) { //Ignore for now } } try { $data = $ctrl->{$action}(); } catch (ValidationException $e) { //Do nothing... } catch (Interrupt $e) { //Do nothing... } catch (ErrorException $e) { MessageHandler::instance()->addError($e->getMessage()); } if (!$data) { $data = $ctrl->getData(); } if (!$ctrl->getSkipView()) { if ($view) { $this->body = $view->render($data); } else { if (!Request::isAjax()) { header("HTTP/1.1 500 View not Found"); throw new Exception(T('View not found: %s', $viewFile)); } } } } catch (HttpNotFoundException $e) { trigger_error(sprintf("Path not found %s", self::getPath()), E_USER_ERROR); if (!Request::isAjax()) { Url::redirect('error', 'notfound'); } Pimple::end(); } catch (Exception $e) { header("HTTP/1.1 500 Internal error"); if (Request::isAjax()) { $this->body = json_encode(array('msg' => $e->getMessage(), 'trace' => $e->getTraceAsString())); } else { if (Settings::get(Settings::DEBUG, false)) { $body = $e->__toString(); if (!stristr($body, '<')) { $body = '<pre>' . $body . '</pre>'; } $this->body = $body; } else { trigger_error(sprintf("Unexpected exception thrown in %s:\n\t%s", self::getPath(), $e->__toString()), E_USER_ERROR); Url::redirect('error', 'internal'); } } } $this->view = new View($appViewFile); }