public static function setUpBeforeClass()
 {
     // Add global vars expected to exist by Slim
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REMOTE_ADDR'] = '?';
     $_SERVER['REQUEST_URI'] = '/';
     $_SERVER['SERVER_NAME'] = '?';
     $_SERVER['SERVER_PORT'] = 80;
     require __DIR__ . '/../../vendor/autoload.php';
     $config = (require __DIR__ . '/../../config.php');
     $config['application.db']['prefix'] = 'test__';
     if (file_exists(__DIR__ . '/config-local.php')) {
         require __DIR__ . '/config-local.php';
     }
     self::$db = \Rocker\Object\DB::instance($config['application.db']);
 }
Beispiel #2
0
}
// Load cli utilities and vendor libraries
require $app_path . 'vendor/autoload.php';
if (function_exists('\\cli\\register_autoload')) {
    // old cli must be autoladed using this function
    \cli\register_autoload();
}
// Shorthand for \cli\line()
if (!function_exists('_')) {
    function _($str)
    {
        \cli\line($str);
    }
}
// Check that we can connect
$db = \Rocker\Object\DB::instance($config['application.db']);
try {
    $tables = $db->executeQuery('SHOW TABLES')->fetchAll();
} catch (\Exception $e) {
    _('%rERROR: Database connection failed%n');
    _($e->getMessage());
    return;
}
// Run class installations
foreach ($config['application.install'] as $class) {
    /* @var \Rocker\Utils\InstallableInterface $obj */
    $obj = new $class($db);
    if ($obj->isInstalled()) {
        _('* ' . $class . ' already installed');
    } else {
        $obj->install();
Beispiel #3
0
 /**
  * Handles request and echos response to client
  * @param array $path
  * @param null|RequestController $controller
  */
 public function dispatch($path, $controller = null)
 {
     try {
         $db = DB::instance($this->config('application.db'));
         $cache = Cache::instance($this->config('application.cache'));
         if ($controller === null) {
             $controller = new RequestController($this, $db, $cache);
         } else {
             $controller->setDatabase($db);
             $controller->setCache($cache);
         }
         // override output content-type in runtime using file extension
         if ($this->config('application.allow_output_extensions') !== false) {
             $path_last_index = count($path) - 1;
             if ($ext = pathinfo($path[$path_last_index], PATHINFO_EXTENSION)) {
                 $this->config('application.output', $ext);
                 $path[$path_last_index] = pathinfo($path[$path_last_index], PATHINFO_FILENAME);
             }
         }
         $controller->handle($path);
     } catch (DuplicationException $e) {
         $response = new OperationResponse(409, array('error' => 'An action causing data duplication was found: ' . $e->getMessage()));
         $controller = new RequestController($this, null, null);
         $controller->handleResponse($response);
     } catch (\InvalidArgumentException $e) {
         $response = new OperationResponse(400, array('error' => $e->getMessage()));
         $controller = new RequestController($this, null, null);
         $controller->handleResponse($response);
     } catch (\Exception $e) {
         ErrorHandler::log($e);
         $mess = array('message' => $e->getMessage());
         if ($this->config('mode') == 'development') {
             $mess['trace'] = $e->getTraceAsString();
         }
         $response = new OperationResponse(500, $mess);
         $controller = new RequestController($this, null, null);
         $controller->handleResponse($response);
     }
 }