Bolt\Controller\Exception::databaseDriver PHP 메소드

databaseDriver() 공개 메소드

public databaseDriver ( string $subtype, string $name, string $driver, string $parameter = null ) : Response
$subtype string
$name string
$driver string
$parameter string
리턴 Symfony\Component\HttpFoundation\Response
    public function databaseDriver($subtype, $name, $driver, $parameter = null)
    {
        if ($this->app === null) {
            throw new \RuntimeException('Exception controller being used outside of request cycle.');
        }
        $context = $this->getContextArray();
        $context['type'] = 'driver';
        $context['subtype'] = $subtype;
        $context['name'] = $name;
        $context['driver'] = $driver;
        $context['parameter'] = $parameter;
        $html = $this->app['twig']->render('@bolt/exception/database/exception.twig', $context);
        return new Response($html, Response::HTTP_OK);
    }

Usage Example

예제 #1
0
파일: Database.php 프로젝트: bolt/bolt
 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;
 }