Пример #1
0
 /**
  * Before exception is happening.
  *
  * @param Event            $event      Event object.
  * @param Dispatcher       $dispatcher Dispatcher object.
  * @param PhalconException $exception  Exception object.
  *
  * @throws \Phalcon\Exception
  * @return bool
  */
 public function beforeException($event, $dispatcher, $exception)
 {
     // Handle 404 exceptions.
     if ($exception instanceof PhDispatchException) {
         $dispatcher->forward(['module' => EngineApplication::SYSTEM_DEFAULT_MODULE, 'namespace' => ucfirst(EngineApplication::SYSTEM_DEFAULT_MODULE) . '\\Controller', 'controller' => 'Error', 'action' => 'show404']);
         return false;
     }
     if (ENV == ENV_DEVELOPMENT) {
         throw $exception;
     } else {
         EngineException::logException($exception);
     }
     // Handle other exceptions.
     $dispatcher->forward(['module' => EngineApplication::SYSTEM_DEFAULT_MODULE, 'namespace' => ucfirst(EngineApplication::SYSTEM_DEFAULT_MODULE) . '\\Controller', 'controller' => 'Error', 'action' => 'show500']);
     return $event->isStopped();
 }
Пример #2
0
 /**
  * Init environment.
  *
  * @param DI     $di     Dependency Injection.
  * @param Config $config Config object.
  *
  * @return Url
  */
 protected function _initEnvironment($di, $config)
 {
     set_error_handler(function ($errorCode, $errorMessage, $errorFile, $errorLine) {
         throw new \ErrorException($errorMessage, $errorCode, 1, $errorFile, $errorLine);
     });
     set_exception_handler(function ($e) use($di) {
         /**
          * Write to log when app in production mode.
          */
         if (ENV == ENV_PRODUCTION) {
             $errorId = EnException::logException($e);
         }
         if ($di->get('app')->isConsole()) {
             echo 'Error <' . $errorId . '>: ' . $e->getMessage();
             return true;
         }
         if (ENV == ENV_DEVELOPMENT) {
             $p = new PrettyExceptions($di);
             $p->setBaseUri('/plugins/pretty-exceptions/');
             return $p->handleException($e);
         }
         return true;
     });
     if ($config->global->profiler) {
         $profiler = new EnProfiler();
         $di->set('profiler', $profiler);
     }
     /**
      * The URL component is used to generate all kind of urls in the
      * application
      */
     $url = new PhUrl();
     $url->setBaseUri($config->global->baseUrl);
     $url->setStaticBaseUri($config->global->staticUrl);
     $di->set('url', $url);
     return $url;
 }
Пример #3
0
 /**
  * Init environment.
  *
  * @param DI     $di     Dependency Injection.
  * @param Config $config Config object.
  *
  * @return Url
  */
 protected function _initEnvironment($di, $config)
 {
     set_error_handler(function ($errorCode, $errorMessage, $errorFile, $errorLine) {
         throw new \ErrorException($errorMessage, $errorCode, 1, $errorFile, $errorLine);
     });
     set_exception_handler(function ($e) use($di) {
         $errorId = Exception::logException($e);
         if ($di->get('app')->isConsole()) {
             echo 'Error <' . $errorId . '>: ' . $e->getMessage();
             return true;
         }
         if (APPLICATION_STAGE == APPLICATION_STAGE_DEVELOPMENT) {
             $p = new PrettyExceptions($di);
             $p->setBaseUri('assets/js/core/pretty-exceptions/');
             return $p->handleException($e);
         }
         return true;
     });
     if ($config->application->profiler && $config->installed) {
         $profiler = new Profiler();
         $di->set('profiler', $profiler);
     }
     /**
      * The URL component is used to generate all kind of urls in the
      * application
      */
     $url = new Url();
     $url->setBaseUri($config->application->baseUrl);
     $di->set('url', $url);
     return $url;
 }