Esempio n. 1
1
 public function setUp()
 {
     $capsule = new Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Esempio n. 2
1
 /**
  * IlluminateのDB接続設定とブートアップ
  * @param array $settings 接続設定
  */
 public static function registerIlluminate(array $settings)
 {
     $capsule = new \Illuminate\Database\Capsule\Manager();
     $capsule->addConnection($settings);
     $capsule->setEventDispatcher(new \Illuminate\Events\Dispatcher(new \Illuminate\Container\Container()));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Esempio n. 3
0
 /**
  * Init Core
  *
  * @uses Stativo\Helpers\Language
  * @uses Stativo\Helpers\File
  * @return \Core Returns instance of Stativo\Core\Core
  */
 public function init()
 {
     // Load env files
     $dotenv = new \Dotenv\Dotenv(DOCROOT, '.env');
     $dotenv->overload();
     // Load config (after \Dotenv)
     $config = self::config('app');
     // Init DB if is set true
     if ($config->get('database')['enabled']) {
         $capsule = new \Illuminate\Database\Capsule\Manager();
         foreach ($config->get('database')['connections'] as $name => $conn) {
             $capsule->addConnection($conn, $name);
         }
         $capsule->setAsGlobal();
         $capsule->bootEloquent();
     }
     // Init translation if set true
     if ($config->get('language')['enabled']) {
         \Stativo\Helpers\Language::instance();
     }
     if (class_exists(\Stativo\Helpers\File::class)) {
         \Stativo\Helpers\File::instance();
     }
     return $this;
 }
Esempio n. 4
0
 public function _initEloquentORM()
 {
     Loader::import("vendor/autoload.php");
     $capsule = new \Illuminate\Database\Capsule\Manager();
     $capsule->addConnection($this->_config->orm->eloquent->toArray());
     $capsule->bootEloquent();
     $capsule->setAsGlobal();
 }
Esempio n. 5
0
 public function setup()
 {
     $db = DbConfig::get_params();
     $capsule = new Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(['driver' => 'mysql', 'host' => $db['host'], 'database' => $db['dbname'], 'username' => $db['username'], 'password' => $db['password'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
     $capsule->setEventDispatcher(new Illuminate\Events\Dispatcher(new Illuminate\Container\Container()));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Esempio n. 6
0
function setupDB()
{
    $config = (include __DIR__ . '/../src/config.php');
    $capsule = new Illuminate\Database\Capsule\Manager();
    $connection = ['driver' => 'sqlite', 'database' => realpath(__DIR__ . '/' . $config['path'] . '/' . $config['db'])];
    $capsule->addConnection($connection, 'calibre');
    $capsule->setAsGlobal();
    $capsule->bootEloquent();
}
Esempio n. 7
0
 function db()
 {
     $capsule = new Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'Library', 'username' => 'root', 'password' => 'hornline', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
     // Make this Capsule instance available globally via static methods
     $capsule->setAsGlobal();
     // Setup the Eloquent ORM
     $capsule->bootEloquent();
 }
Esempio n. 8
0
 public function getSlimInstance()
 {
     $capsule = new Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
     $capsule->setEventDispatcher(new Illuminate\Events\Dispatcher());
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     require __DIR__ . '/../app/schema.php';
     $app = new \Slim\Slim(['debug' => false, 'mode' => 'testing', 'templates.path' => __DIR__ . '/../views']);
     $app->setName('default');
     require __DIR__ . '/../app/app.php';
     return $app;
 }
Esempio n. 9
0
 public function register(\Exedra\Application $app)
 {
     $app->wizard->add(\Laraquent\Support\Exedra\Wizard::class);
     if (!$app->config->has('db')) {
         throw new \Exception('db. configuration is required.');
     }
     $config = $app->config;
     $capsule = new \Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(array('driver' => $config->get('db.driver', 'mysql'), 'host' => $config->get('db.host', 'localhost'), 'database' => $config->get('db.name'), 'username' => $config->get('db.user'), 'password' => $config->get('db.pass'), 'charset' => $config->get('db.charset', 'utf8'), 'collation' => $config->get('db.collation', 'utf8_unicode_ci')));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     // register eloquent
     $app->eloquent = $capsule;
 }
Esempio n. 10
0
 public function __construct()
 {
     parent::__construct(['mode' => 'production']);
     // setup database connection
     $capsule = new \Illuminate\Database\Capsule\Manager();
     $capsule->addConnection(array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'resapi', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => ''));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     // add middleware
     $this->add(new MiddlewareMediatype());
     $this->add(new MiddlewareAuthenticator());
     // add error message
     $this->notFound(function () {
         echo json_encode(['errmsg' => 'Not Found Request']);
     });
     Routing::setupRouting($this);
 }
 public static function setUpBeforeClass()
 {
     $connection = [];
     switch (getenv('DB_ADAPTER')) {
         case 'sqlite':
             $connection['driver'] = 'sqlite';
             $connection['database'] = getenv('DB_NAME');
             break;
         case 'mysql':
             $connection['driver'] = 'mysql';
             $connection['host'] = getenv('DB_HOST');
             $connection['port'] = getenv('DB_PORT');
             $connection['database'] = getenv('DB_NAME');
             $connection['username'] = getenv('DB_USER');
             $connection['password'] = getenv('DB_PASS');
             $connection['charset'] = getenv('DB_CHARSET');
             $connection['collation'] = getenv('DB_COLLATION');
             break;
     }
     $capsule = new \Illuminate\Database\Capsule\Manager();
     $capsule->addConnection($connection);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Esempio n. 12
0
    $php_cfg = cfg('config')->php;
    if ($php_cfg->count() > 0) {
        foreach ($php_cfg->toArray() as $key => $val) {
            $key = str_replace('__', '.', $key);
            @ini_set($key, $val);
        }
        unset($key, $val);
    }
    unset($php_cfg);
}
unset($DisabledFunctions);
require CORE_PATH . DIR_SEP . 'smarty_security.php';
require CORE_LIBRARY_DIR . DIR_SEP . 'ui.php';
$config = cfg('dbase');
$events = new \Illuminate\Events\Dispatcher();
if ($config->count() > 0) {
    $database = new \Illuminate\Database\Capsule\Manager();
    foreach ($config->toArray() as $key => $val) {
        $database->addConnection(['driver' => 'mysql', 'host' => $val->host, 'database' => $val->database, 'username' => $val->username, 'password' => $val->password, 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => $val->prefix], strtolower($key));
    }
    $database->setAsGlobal();
    $database->bootEloquent();
    $database->setEventDispatcher($events);
    class_alias('\\Illuminate\\Database\\Capsule\\Manager', '\\Wasp\\DB');
    class_alias('\\Illuminate\\Database\\Schema\\Builder', '\\Wasp\\Schema');
    require CORE_LIBRARY_DIR . DIR_SEP . 'model.php';
    if (DEVELOP_MODE) {
        \Wasp\DB::enableQueryLog();
    }
}
app()->execute();
Esempio n. 13
0
 protected function registerDefaultContainerItems()
 {
     $this->container['migration-table'] = 'migrations';
     $this->container['migrations-path'] = null;
     $this->container['environment'] = function ($c) {
         global $argv;
         $environment = 'production';
         if (!empty($argv[2]) && preg_match('/--database=(.*?)$/si', $argv[2], $matches)) {
             $environment = $matches[1];
             unset($argv[2]);
         }
         return $environment;
     };
     $this->container['db-config'] = function ($c) {
         require_once $c['config-path'] . $c['environment'] . '.php';
         return ['driver' => 'mysql', 'host' => $db['host'], 'database' => $db['database'], 'username' => $db['username'], 'password' => $db['password'], 'charset' => 'utf8', 'prefix' => '', 'collation' => 'utf8_general_ci', 'schema' => 'public'];
     };
     $this->container['filesystem'] = function ($c) {
         return new \Illuminate\Filesystem\Filesystem();
     };
     $this->container['composer'] = function ($c) {
         $composer = new \Illuminate\Support\Composer($c['filesystem']);
         return $composer;
     };
     $this->container['builder'] = function ($c) {
         $builder = new \Illuminate\Database\Schema\Builder($c['connection']);
         return $builder;
     };
     $this->container['connection'] = function ($c) {
         $manager = new \Illuminate\Database\Capsule\Manager();
         $manager->addConnection($c['db-config']);
         $manager->setAsGlobal();
         $manager->bootEloquent();
         return $manager->getConnection('default');
     };
     $this->container['resolver'] = function ($c) {
         $r = new \Illuminate\Database\ConnectionResolver([$c['environment'] => $c['connection']]);
         $r->setDefaultConnection($c['environment']);
         return $r;
     };
     $this->container['migration-repo'] = function ($c) {
         return new \Illuminate\Database\Migrations\DatabaseMigrationRepository($c['resolver'], $c['migration-table']);
     };
     $this->container['migration-creator'] = function ($c) {
         return new \Illuminate\Database\Migrations\MigrationCreator($c['filesystem']);
     };
     $this->container['migrator'] = function ($c) {
         return new \Illuminate\Database\Migrations\Migrator($c['migration-repo'], $c['resolver'], $c['filesystem']);
     };
     $this->container['install-command'] = function ($c) {
         $command = new Migrations\InstallCommand($c['migration-repo']);
         $command->setLaravel(new FakeLaravel($command, $c['migrations-path']));
         return $command;
     };
     $this->container['migrate-make-command'] = function ($c) {
         $command = new Migrations\MigrateMakeCommand($c['migration-creator'], $c['composer']);
         $command->setLaravel(new FakeLaravel($command, $c['migrations-path']));
         return $command;
     };
     $this->container['migrate-command'] = function ($c) {
         $command = new Migrations\MigrateCommand($c['migrator']);
         $command->setLaravel(new FakeLaravel($command, $c['migrations-path']));
         return $command;
     };
 }
Esempio n. 14
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$capsule = new Illuminate\Database\Capsule\Manager();
$capsule->addConnection(require __DIR__ . '/config/database.php');
$capsule->setEventDispatcher(new Illuminate\Events\Dispatcher(new Illuminate\Container\Container()));
$capsule->bootEloquent();
$capsule->setAsGlobal();
$__autoload_paths = array('models', 'migrators', 'seeders');
foreach ($__autoload_paths as $path) {
    foreach (glob(__DIR__ . "/{$path}/*.php") as $dep) {
        require_once $dep;
    }
}
require __DIR__ . '/suite/CommentableTestCase.php';
Esempio n. 15
0
<?php

// DIC configuration
$container = $app->getContainer();
// view renderer
$container['renderer'] = function ($c) {
    $settings = $c->get('settings')['renderer'];
    return new Slim\Views\PhpRenderer($settings['template_path']);
};
// monolog
$container['logger'] = function ($c) {
    $settings = $c->get('settings')['logger'];
    $logger = new Monolog\Logger($settings['name']);
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], Monolog\Logger::DEBUG));
    return $logger;
};
// database
$container['db'] = function ($c) {
    $settings = $c->get('database')['mysql'];
    $db = new \Illuminate\Database\Capsule\Manager();
    $db->addConnection($settings);
    $db->setAsGlobal();
    $db->bootEloquent();
    return $db;
};
Esempio n. 16
0
<?php

$config = [];
$config['eloquentModelTemplate'] = function ($container) {
    return file_get_contents(realpath(__DIR__ . '/../templates') . '/ModelTemplate.txt');
};
$config['SlimApi\\Model\\ModelInterface'] = function ($container) {
    return new \SlimApi\Eloquent\Model\EloquentModelService($container->get('eloquentModelTemplate'), $container->get('namespace'));
};
$config['database.configForEloquent'] = function ($container) {
    $standardisedConfig = $container['database.config'];
    $eloquentConfig = ['driver' => $standardisedConfig['adapter'], 'host' => $standardisedConfig['host'], 'database' => $standardisedConfig['name'], 'username' => $standardisedConfig['user'], 'password' => $standardisedConfig['pass'], 'charset' => $standardisedConfig['charset'], 'collation' => 'utf8_unicode_ci', 'prefix' => ''];
    return $eloquentConfig;
};
$config['database.connectEloquent'] = function ($container) {
    $config = $container['database.configForEloquent'];
    $manager = new \Illuminate\Database\Capsule\Manager();
    $manager->addConnection($config);
    // Set the event dispatcher used by Eloquent models... (optional)
    $manager->setEventDispatcher(new \Illuminate\Events\Dispatcher(new \Illuminate\Container\Container()));
    // Make this Capsule instance available globally via static methods... (optional)
    $manager->setAsGlobal();
    // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
    $manager->bootEloquent();
    return $manager;
};
$config['SlimApi\\Eloquent\\Init'] = function ($container) {
    $container['database.connectEloquent'];
};
return $config;
Esempio n. 17
0
 /**
  * 初始化数据库分发器
  * @function _initDefaultDbAdapter
  * @author   jsyzchenchen@gmail.com
  */
 public function _initDefaultDbAdapter()
 {
     //初始化 illuminate/database
     $capsule = new \Illuminate\Database\Capsule\Manager();
     $capsule->addConnection($this->config->database->toArray());
     $capsule->setEventDispatcher(new \Illuminate\Events\Dispatcher(new \Illuminate\Container\Container()));
     $capsule->setAsGlobal();
     //开启Eloquent ORM
     $capsule->bootEloquent();
     class_alias('\\Illuminate\\Database\\Capsule\\Manager', 'DB');
 }
Esempio n. 18
0
 protected function boot()
 {
     $this->database->setAsGlobal();
     $this->database->bootEloquent();
 }