Exemple #1
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;
 }
 /**
  * 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;
 }