/**
  * 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();
 }
Example #2
0
 /**
  * Dispatch.
  * Override it to use own logic.
  *
  * @throws \Exception
  * @return object
  */
 public function dispatch()
 {
     try {
         $parts = explode('_', $this->_handlerName);
         $finalHandlerName = '';
         foreach ($parts as $part) {
             $finalHandlerName .= ucfirst($part);
         }
         $this->_handlerName = $finalHandlerName;
         $this->_actionName = strtolower($this->_actionName);
         return parent::dispatch();
     } catch (\Exception $e) {
         $this->_handleException($e);
         if (ENV == ENV_DEVELOPMENT) {
             throw $e;
         } else {
             $id = Exception::logError('Exception', $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
             $this->getDI()->setShared('currentErrorCode', function () use($id) {
                 return $id;
             });
         }
     }
     return parent::dispatch();
 }
Example #3
0
 /**
  * Log exception
  *
  * @param \Exception $exception
  */
 public static function exception($exception)
 {
     // Log the error
     self::logError('Exception', $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString());
     // Display it
 }
Example #4
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;
 }
Example #5
0
 /**
  * Log exception.
  *
  * @param \Exception $e Exception object.
  *
  * @return string
  */
 public static function logException(\Exception $e)
 {
     return self::logError('Exception', $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
 }
Example #6
0
 /**
  * handle script ending exception
  *
  * @param \Exception $e
  * @param $taskId
  * @param code $exit
  * @internal param that $Exception caused the failure
  * @internal param of $id the task you started
  * @internal param code $exit status of the process
  */
 protected function handleException(\Exception $e, $taskId, $exit)
 {
     $sub = '%s[ERROR]%s %s file: %s line: %d';
     // Remove Process Instance
     if ($e->getCode() != self::ERROR_SINGLE) {
         $this->removeProcessInstance();
     }
     $msg = sprintf($sub, Output::COLOR_RED, Output::COLOR_NONE, $e->getMessage(), $e->getFile(), $e->getLine());
     // Let user that ran this know it failed
     Output::stderr($msg);
 }
 /**
  * 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;
 }