Ejemplo n.º 1
0
 /**
  * Handles external error caused by end-users.
  * This method overrides the parent implementation.
  * It is invoked by PRADO when an external exception is thrown.
  */
 protected function handleExternalError($statusCode, $exception)
 {
     // log the error (only for BlogException)
     if ($exception instanceof BlogException) {
         Prado::log($exception->getErrorMessage(), TLogger::ERROR, 'BlogApplication');
     }
     // call parent implementation to display the error
     parent::handleExternalError($statusCode, $exception);
 }
Ejemplo n.º 2
0
 /**
  * Displays error to the client user.
  * THttpException and errors happened when the application is in <b>Debug</b>
  * mode will be displayed to the client user.
  * @param integer response status code
  * @param Exception exception instance
  */
 protected function handleExternalError($statusCode, $exception)
 {
     if ($exception instanceof BlogException) {
         $message = $exception->getMessage();
         Prado::log($message, TLogger::ERROR, 'BlogApplication');
         $message = urldecode($this->getApplication()->getSecurityManager()->hashData($message));
         $this->Response->redirect($this->Service->constructUrl('ErrorReport', array('msg' => $message), false));
     } else {
         parent::handleExternalError($statusCode, $exception);
     }
 }
Ejemplo n.º 3
0
 /**
  * Loads a page instance.
  * This method will create a page instance or load it from memory.
  * If the page name contains module ID, the module will be also loaded.
  * Errors happened during the loading will be handled using the error handler.
  * @param string the page name (either PageType or ModuleName:PageType).
  * @return TPage the loaded page instance
  * @see createComponent()
  */
 public function loadPage($type)
 {
     if (isset($this->pages[$type])) {
         return $this->pages[$type];
     }
     $type = trim($type, ':');
     $pos = strpos($type, ':');
     if ($pos === false) {
         $moduleName = '';
         $pageName = $type;
     } else {
         $moduleName = substr($type, 0, $pos);
         $pageName = substr($type, $pos + 1);
     }
     try {
         if (empty($pageName)) {
             throw new TPageNotDefinedException("[empty]");
         }
         // user authentication
         $role = $this->getRequiredRole($moduleName, $pageName);
         if (!is_null($role)) {
             if (!$this->user->isAuthenticated()) {
                 $this->user->onAuthenticationRequired($type);
                 $this->errorHandler->handleError(TErrorHandler::CASE_UNAUTHORIZED, new TPageUnauthorizedException($type));
             }
         }
         // creating the module and page objects
         $module = empty($moduleName) ? null : $this->loadModule($moduleName);
         if (!pradoImportClass($pageName)) {
             throw new TPageNotDefinedException($pageName);
         }
         $page = $this->createComponent($pageName, $pageName);
         if (!$page instanceof TPage) {
             // will use is_subclass_of since PHP 5.0.3
             throw new TPageNotDefinedException($pageName);
         }
         $page->setModule($module);
         // page authorization
         $authorized = is_null($role) ? true : $this->user->isInRole($role);
         if ($authorized) {
             $authorized = $page->onAuthorize($this->user);
         }
         if ($authorized) {
             return $page;
         } else {
             $this->user->onAuthorizationRequired($page);
             $this->errorHandler->handleError(TErrorHandler::CASE_UNAUTHORIZED, new TPageUnauthorizedException($type));
         }
     } catch (TPageNotDefinedException $e) {
         $this->errorHandler->handleError(TErrorHandler::CASE_PAGENOTFOUND, $e);
     } catch (TModuleNotDefinedException $e) {
         $this->errorHandler->handleError(TErrorHandler::CASE_PAGENOTFOUND, $e);
     } catch (Exception $e) {
         $this->errorHandler->handleError(TErrorHandler::CASE_INTERNALERROR, $e);
     }
 }