Example #1
0
 public static function getStore()
 {
     if (!static::$store) {
         $manager = new CacheManager(new ConfigContainer(array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Encrypter::getInstance(), 'config' => array('cache.driver' => 'database', 'cache.prefix' => 'schema_', 'cache.stores.database' => array('driver' => 'database', 'connection' => 'default', 'table' => 'cache')))));
         static::$store = $manager->driver('database')->getStore();
     }
     return static::$store;
 }
Example #2
0
 /**
  * Specify a unique index for the table.
  *
  * @param  string|array  $columns
  * @param  string  $name
  * @return \Illuminate\Support\Fluent
  */
 public function spatialIndex($columns, $name = null)
 {
     $connection_klass = get_class(\DLModel::getConnectionResolver()->connection());
     if ($connection_klass == 'Illuminate\\Database\\MySqlConnection') {
         // MySQL: Only MyISAM engine have spatial indexing
         $this->engine = 'MyISAM';
     }
     return $this->indexCommand('spatial', $columns, $name);
 }
Example #3
0
File: Cache.php Project: endel/hook
 public static function getInstance()
 {
     if (!static::$instance) {
         $connection = \DLModel::getConnectionResolver()->connection();
         $cache_manager = $connection->getCacheManager();
         $default_driver = $cache_manager->getDefaultDriver();
         static::$instance = $cache_manager->driver($default_driver);
     }
     return static::$instance;
 }
Example #4
0
 public static function getManager($driver = null)
 {
     if (!static::$manager) {
         if (!$driver) {
             $driver = \Slim\Slim::getInstance()->config('cache');
         }
         if ($driver == "filesystem") {
             $config = array('files' => new Filesystem(), 'config' => array('cache.driver' => 'file', 'cache.path' => storage_dir() . '/cache'));
         } else {
             if ($driver == "database") {
                 $config = array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Encrypter::getInstance(), 'config' => array('cache.default' => 'database', 'cache.prefix' => '', 'cache.stores.database' => array('driver' => 'database', 'connection' => 'default', 'table' => 'cache')));
             }
         }
         $container = new ConfigContainer($config);
         static::$manager = new CacheManager($container);
     }
     return static::$manager;
 }
Example #5
0
 /**
  * isSupported
  *
  * @return bool
  */
 public function isSupported()
 {
     $connection = \DLModel::getConnectionResolver()->connection();
     return !is_null($connection->getPdo());
 }
Example #6
0
 /**
  * migrate
  *
  * Migrate core application schema.
  */
 public static function migrate()
 {
     $connection = \DLModel::getConnectionResolver()->connection();
     if ($connection->getPdo()) {
         $builder = $connection->getSchemaBuilder();
         if (!$builder->hasTable('modules')) {
             foreach (glob(__DIR__ . '/../../migrations/app/*.php') as $file) {
                 $migration = (require $file);
                 if (is_array($migration)) {
                     $builder->create($connection->getTablePrefix() . key($migration), current($migration));
                 }
             }
         }
     }
 }
Example #7
0
 protected function registerEnumDoctrineType($table, $field_name, $allowed = array())
 {
     //
     // WORKAROUND:
     // register unsupported ENUM as a doctrine supported type
     // related issue: https://github.com/laravel/framework/issues/1186
     //
     $enum_klass_name = 'Enum' . ucfirst($table) . ucfirst($field_name);
     if (!$allowed || empty($allowed)) {
         throw new MethodFailureException('Missing "allowed" values for ENUM type: ' . $table . '#' . $field_name . '.');
     }
     $allowed_json = json_encode($allowed);
     $enum_name = 'enum';
     // . $field_name;
     eval('class ' . $enum_klass_name . ' extends Hook\\Database\\Types\\EnumType {
             protected $name = \'' . $enum_name . '\';
             protected $values = array(' . substr($allowed_json, 1, strlen($allowed_json) - 2) . ');
     }');
     $type_method = 'addType';
     if (\Doctrine\DBAL\Types\Type::hasType('enum')) {
         $type_method = 'overrideType';
     }
     call_user_func_array(array('\\Doctrine\\DBAL\\Types\\Type', $type_method), array('enum', $enum_klass_name));
     //
     // WORKAROUND:
     // Need to register 'enum' on AbstractPlatform with anything different
     // than the real type, in order find diffs via:
     // `Illuminate\Database\Schema\Grammars\Grammar#compileChange`
     //
     $connection = \DLModel::getConnectionResolver()->connection();
     $connection->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'blob');
     return $enum_klass_name;
 }
Example #8
0
 public function __construct()
 {
     $this->connection = \DLModel::getConnectionResolver()->connection();
 }
Example #9
0
$config = (require ROOT_DIR . '/config/preferences.php');
date_default_timezone_set($config['timezone']);
if ($config['debug']) {
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
}
$config['log.enabled'] = $config['debug'];
// Merge settings with security config
$config = array_merge($config, require ROOT_DIR . '/config/security.php');
$app = new \Slim\Slim($config);
$app->config('database', require ROOT_DIR . '/config/database.php');
$app->config('paths', require ROOT_DIR . '/config/paths.php');
Hook\Http\Router::setInstance($app);
require ROOT_DIR . '/vendor/doubleleft/hook/src/bootstrap/connection.php';
// setup custom pagination environment
$connection = \DLModel::getConnectionResolver()->connection();
$connection->setPaginator(new Hook\Framework\Environment());
// Set application key
$app_key = null;
$config_keys = ROOT_DIR . '/config/keys.php';
// auto-set app_id/key
if (!$app->request->headers->get('X-App-Id')) {
    // Create default application if it doesn't exists
    if (Hook\Model\AppKey::count() == 0) {
        $application = Hook\Model\App::create(array('name' => "Application"));
        $hook_config = $application->keys[0]->toArray();
        $hook_config['endpoint'] = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
        file_put_contents($app->config('paths')['root'] . '.hook-config', json_encode($hook_config));
        // Migrate application tables
        Hook\Application\Context::setKey($application->keys[0]);
        Hook\Application\Context::migrate();
Example #10
0
// Use a string representing an RFC2822 or ISO 8601 date
// http://tools.ietf.org/html/rfc2822#page-14
//
\Carbon\Carbon::setToStringFormat('Y-m-d\\TH:i:sP');
// Setup paginator
$connection->setPaginator(new Hook\Pagination\Environment());
// Setup Schema Grammar
// $connection->setSchemaGrammar();
// Setup cache manager
$connection->setCacheManager(function () {
    $cache_driver = Router::config('cache');
    if ($cache_driver == "filesystem") {
        $config = array('files' => new \Illuminate\Filesystem\Filesystem(), 'config' => array('cache.driver' => 'file', 'cache.path' => storage_dir() . '/cache'));
    } else {
        if ($cache_driver == "database") {
            $config = array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Hook\Security\Encryption\Encrypter::getInstance(), 'config' => array('cache.driver' => 'database', 'cache.connection' => 'default', 'cache.table' => 'cache', 'cache.prefix' => ''));
        }
    }
    return new Illuminate\Cache\CacheManager($config);
});
//
// TODO: Create `hook migrate` command.
// --------------------------------------
//
//
// Try to create schema.
// Ignore NoSQL databases.
//
if ($connection->getPdo()) {
    $builder = $connection->getSchemaBuilder();
    if (!$builder->hasTable('apps')) {
Example #11
0
    }
    if (isset($parts['path'])) {
        $db_config['database'] = substr($parts['path'], 1);
    }
}
// ------------------
// MongoDB connection
// ------------------
if ($db_config['driver'] == 'mongodb') {
    $connection = new Jenssegers\Mongodb\Connection($db_config);
    class_alias('\\Jenssegers\\Mongodb\\Model', 'DLModel');
    $resolver = new \Illuminate\Database\ConnectionResolver(array('default' => $connection));
    $resolver->addConnection('app', $connection);
    $resolver->setDefaultConnection('default');
    DLModel::setConnectionResolver($resolver);
    DLModel::setEventDispatcher($event_dispatcher);
    $connection->setEventDispatcher($event_dispatcher);
} else {
    //
    // Create SQLite database
    //
    if ($db_config['driver'] == 'sqlite') {
        touch($db_config['database']);
    }
    $capsule = new Illuminate\Database\Capsule\Manager();
    $capsule->addConnection($db_config);
    $capsule->setFetchMode(PDO::FETCH_CLASS);
    $capsule->setEventDispatcher($event_dispatcher);
    $capsule->setAsGlobal();
    $capsule->bootEloquent();
    $connection = $capsule->connection();