Автор: Gawain Lynch (gawain.lynch@gmail.com)
Наследование: extends Base, implements Bolt\Controller\ExceptionControllerInterface
Пример #1
0
 public function setUp()
 {
     $this->_filesystem = PHPUnit_Extension_FunctionMocker::start($this, 'Symfony\\Component\\Filesystem')->mockFunction('file_exists')->mockFunction('is_dir')->mockFunction('is_readable')->mockFunction('is_writable')->mockFunction('rmdir')->mockFunction('touch')->mockFunction('unlink')->getMock();
     $this->_validation = PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\\Configuration\\Validation')->mockFunction('extension_loaded')->mockFunction('file_exists')->mockFunction('get_magic_quotes_gpc')->mockFunction('ini_get')->mockFunction('is_dir')->mockFunction('is_readable')->mockFunction('is_writable')->mockFunction('rmdir')->mockFunction('touch')->mockFunction('unlink')->getMock();
     $this->extensionController = $this->prophesize(Controller\Exception::class);
     $this->config = $this->prophesize(Config::class);
     $this->resourceManager = $this->prophesize(ResourceManager::class);
     $this->validator = new Validator($this->extensionController->reveal(), $this->config->reveal(), $this->resourceManager->reveal());
 }
Пример #2
0
 /**
  * Event fired on database connection failure.
  *
  * @param FailedConnectionEvent $args
  *
  * @throws BootException
  */
 public function failConnect(FailedConnectionEvent $args)
 {
     $e = $args->getException();
     $this->logger->debug($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
     /*
      * Using Driver here since Platform may try to connect
      * to the database, which has failed since we are here.
      */
     $platform = $args->getDriver()->getName();
     $platform = Str::replaceFirst('pdo_', '', $platform);
     $response = $this->exceptionController->databaseConnect($platform, $e);
     throw new BootException($e->getMessage(), $e->getCode(), $e, $response);
 }
Пример #3
0
 /**
  * Handle errors thrown in the application.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->isProfilerRequest($event->getRequest())) {
         return;
     }
     $exception = $event->getException();
     $message = $exception->getMessage();
     $statusCode = Response::HTTP_INTERNAL_SERVER_ERROR;
     if ($exception instanceof HttpExceptionInterface) {
         $statusCode = $exception->getStatusCode();
     }
     // Log the error message
     $level = LogLevel::CRITICAL;
     if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
         $level = LogLevel::WARNING;
     }
     $this->logger->log($level, $message, ['event' => 'exception', 'exception' => $exception]);
     // Get and send the response
     if ($this->isJsonRequest($event->getRequest())) {
         $response = new JsonResponse(['success' => false, 'errorType' => get_class($exception), 'code' => $statusCode, 'message' => $message]);
     } elseif ($this->config->get('general/debug_error_use_symfony')) {
         return null;
     } else {
         $response = $this->exceptionController->kernelException($event);
     }
     $response->setStatusCode($statusCode);
     $event->setResponse($response);
 }
Пример #4
0
 /**
  * Handle errors thrown in the application.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->isProfilerRequest($event->getRequest())) {
         return;
     }
     // Log the error message
     $exception = $event->getException();
     $message = $exception->getMessage();
     $level = LogLevel::CRITICAL;
     if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
         $level = LogLevel::WARNING;
     }
     $this->logger->log($level, $message, ['event' => 'exception', 'exception' => $exception]);
     // Get and send the response
     $response = $this->exceptionController->kernelException($event);
     $event->setResponse($response);
 }
Пример #5
0
 protected function doDatabaseSqliteCheck(Controller\Exception $exceptionController, array $dbConfig)
 {
     if (extension_loaded('pdo_sqlite') === false) {
         return $exceptionController->databaseDriver('missing', 'SQLite', 'pdo_sqlite');
     }
     // If in-memory connection, skip path checks
     if (isset($dbConfig['memory']) && $dbConfig['memory'] === true) {
         return null;
     }
     $fs = new Filesystem();
     $file = $dbConfig['path'];
     // If the file is present, make sure it is writable
     if ($fs->exists($file)) {
         try {
             $fs->touch($file);
         } catch (IOException $e) {
             return $exceptionController->databasePath('file', $file, 'is not writable');
         }
         return null;
     }
     // If the file isn't present, make sure the directory
     // exists and is writable so the file can be created
     $dir = dirname($file);
     if (!$fs->exists($dir)) {
         // At this point, it is possible that the site has been moved and
         // the configured Sqlite database file path is no longer relevant
         // to the site's root path
         $cacheJson = $this->resourceManager->getPath('cache/config-cache.json');
         if ($fs->exists($cacheJson)) {
             $fs->remove($cacheJson);
             $this->config->initialize();
             if (!$fs->exists($dir)) {
                 return $exceptionController->databasePath('folder', $dir, 'does not exist');
             }
         } else {
             return $exceptionController->databasePath('folder', $dir, 'does not exist');
         }
     }
     try {
         $fs->touch($dir);
     } catch (IOException $e) {
         return $exceptionController->databasePath('folder', $dir, 'is not writable');
     }
     return null;
 }
Пример #6
0
 /**
  * Get an exception trace that is safe to display publicly.
  *
  * @param \Exception $exception
  *
  * @return array
  */
 protected function getSafeTrace(\Exception $exception)
 {
     if (!$this->app['debug'] && !($this->app['session']->isStarted() && $this->app['session']->has('authentication'))) {
         return [];
     }
     $rootPath = $this->app['resources']->getPath('root');
     $trace = $exception->getTrace();
     foreach ($trace as $key => $value) {
         $trace[$key]['args_safe'] = $this->getSafeArguments($trace[$key]['args']);
         // Don't display the full path, trim 64-char hexadecimal file names.
         if (isset($trace[$key]['file'])) {
             $trace[$key]['file'] = str_replace($rootPath, '[root]', $trace[$key]['file']);
             $trace[$key]['file'] = preg_replace('/([0-9a-f]{16})[0-9a-f]{48}/i', '\\1…', $trace[$key]['file']);
         }
     }
     return $trace;
 }
Пример #7
0
 /**
  * Get the exception trace that is safe to display publicly.
  *
  * @param \Exception  $exception
  *
  * @return array
  */
 protected function getSafeTrace(\Exception $exception)
 {
     if (!$this->app['debug'] && !($this->app['session']->isStarted() && $this->app['session']->has('authentication'))) {
         return [];
     }
     $rootPath = $this->app['resources']->getPath('root');
     $trace = $exception->getTrace();
     foreach ($trace as $key => $value) {
         unset($trace[$key]['args']);
         // Don't display the full path.
         if (isset($trace[$key]['file'])) {
             $trace[$key]['file'] = str_replace($rootPath, '[root]', $trace[$key]['file']);
         }
     }
     return $trace;
 }