Esempio n. 1
0
 public function init()
 {
     $this->capsule = new Capsule();
     $this->capsule->addConnection(['driver' => 'mysql', 'host' => DB_HOST, 'port' => DB_PORT, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => DB_CHARSET, 'collation' => DB_COLLATION]);
     $this->capsule->bootEloquent();
     $this->capsule->setAsGlobal();
 }
Esempio n. 2
0
 private function __construct()
 {
     $this->capsule = new Capsule();
     $this->capsule->addConnection(['driver' => 'mysql', 'host' => DB_HOST, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
     $this->capsule->setEventDispatcher(new Dispatcher(new Container()));
     $this->capsule->setAsGlobal();
 }
Esempio n. 3
0
 /**
  * Setup eloquent database
  * @param \Illuminate\Database\Capsule\Manager $capsule
  * @throws \Lassi\App\Exception\NotFoundException
  * @return \Lassi\App\Database
  */
 private function _makeEloquent(Capsule $capsule)
 {
     // Throw exception if minimum requirements not met
     if (!getenv('db_driver') || !getenv('db_name')) {
         throw new NotFoundException('App configurations not found.');
     }
     // Get capsule instance
     $this->capsule = $capsule;
     // Cache db driver
     $db_driver = getenv('db_driver');
     // Setup connection defaults
     $configs = array('driver' => $db_driver, 'database' => getenv('db_name'), 'prefix' => getenv('db_prefix'), 'charset' => getenv('db_charset'), 'collation' => getenv('db_collation'));
     // Add extras depending on type of driver/connection
     if ($db_driver !== 'sqlite') {
         if (getenv('db_host')) {
             $configs['host'] = getenv('db_host');
         }
         if (getenv('db_username')) {
             $configs['username'] = getenv('db_username');
         }
         if (getenv('db_password')) {
             $configs['password'] = getenv('db_password');
         }
     }
     // Setup connection
     $this->capsule->addConnection($configs);
     // Set as global
     $this->capsule->setAsGlobal();
     // Boot eloquent
     $this->capsule->bootEloquent();
     return $this;
 }
Esempio n. 4
0
 /**
  * Initializes the connection manager and its dependencies.
  */
 protected function initialize()
 {
     $this->capsule = new Capsule();
     $this->capsule->setEventDispatcher(new Dispatcher(new Container()));
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
 }
Esempio n. 5
0
 protected function setConnection(array $connection)
 {
     $this->capsule = new Capsule();
     $this->capsule->addConnection($connection);
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
 }
 /**
  * {@inheritdoc}
  */
 public function bootstrap($app)
 {
     $this->capsule = new Manager();
     $this->capsule->addConnection(['driver' => $this->driver, 'host' => $this->host, 'database' => $this->database, 'username' => $this->username, 'password' => $this->password, 'charset' => $this->charset, 'collation' => $this->collation, 'prefix' => $this->prefix]);
     $this->capsule->setEventDispatcher(new Dispatcher(new Container()));
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
     $app->set('db', $this->capsule);
 }
Esempio n. 7
0
 /**
  * set up eloquent for test
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     self::$manager = new Manager();
     // TODO: add dotenv and extract for reuse
     self::$manager->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'grimm', 'username' => 'homestead', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null]);
     self::$manager->setAsGlobal();
     self::$manager->bootEloquent();
 }
Esempio n. 8
0
 /**
  * @return \Illuminate\Database\Capsule\Manager
  */
 public function getCapsule()
 {
     if (!$this->capsule) {
         $this->capsule = new Capsule();
         $this->capsule->addConnection($this->configuration);
         $this->capsule->setAsGlobal();
     }
     return $this->capsule;
 }
Esempio n. 9
0
 protected function createConnection()
 {
     $this->capsule = new Capsule();
     $this->capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/db/testing.sqlite', 'prefix' => '']);
     $this->capsule->setFetchMode(PDO::FETCH_CLASS);
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
     $this->capsule->getConnection()->enableQueryLog();
 }
 /**
  * @param array $credentials
  */
 public function addDbConnection($credentials = [])
 {
     if (empty($credentials)) {
         $bitrixDbCredentials = \Bitrix\Main\Application::getInstance()->getConnection()->getConfiguration();
         $credentials = ['driver' => 'mysql', 'database' => $bitrixDbCredentials['database'], 'username' => $bitrixDbCredentials['login'], 'password' => $bitrixDbCredentials['password'], 'host' => $bitrixDbCredentials['host'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false];
     }
     $this->capsule->addConnection($credentials);
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
 }
Esempio n. 11
0
 /**
  * Database constructor.
  */
 public function __construct()
 {
     $this->capsule = new Manager();
     /**
      * Add a connection
      */
     $this->capsule->addConnection($this->GetDatabaseSettings());
     /**
      * Globalise it
      */
     $this->capsule->setAsGlobal();
 }
Esempio n. 12
0
 /**
  * @return \Illuminate\Database\Capsule\Manager
  */
 public static function instance()
 {
     if (static::$_instance === null) {
         $config = Config::get("database");
         static::$_instance = new \Illuminate\Database\Capsule\Manager();
         if ($config["connections"] && is_array($config["connections"])) {
             foreach ($config["connections"] as $key => $cfg) {
                 static::$_instance->addConnection($cfg, $key);
             }
         }
         static::$_instance->setAsGlobal();
     }
     return static::$_instance;
 }
Esempio n. 13
0
 /**
  * Create the connection
  *
  * @return bool
  */
 public function CreateConnection()
 {
     $information = $this->GetInformation();
     if ($information == null) {
         return false;
     }
     try {
         $this->database->addConnection($information);
         $this->database->setAsGlobal();
     } catch (\Exception $error) {
         return false;
     }
     return true;
 }
Esempio n. 14
0
 /**
  * Adds a connection
  */
 public function AddConnection()
 {
     /**
      * Lets get our database settings
      */
     $settings = Settings::GetDatabaseSettings();
     /**
      * Then lets start a connection
      */
     $this->capsule->addConnection($settings);
     /**
      * Then lets globalise this connection
      */
     $this->capsule->setAsGlobal();
 }
Esempio n. 15
0
 /**
  * Init capsule
  */
 public function initCapsule()
 {
     $this->capsule = new Capsule();
     switch ($this->configDatabase['driver']) {
         case 'mysql':
             $configConnection = ['driver' => 'mysql', 'host' => $this->configDatabase['host'], 'database' => $this->configDatabase['database'], 'username' => $this->configDatabase['username'], 'password' => $this->configDatabase['password'], 'charset' => $this->configDatabase['charset'], 'collation' => $this->configDatabase['collation']];
             if (isset($this->configDatabase['prefix'])) {
                 $configConnection['prefix'] = $this->configDatabase['prefix'];
             }
             $this->capsule->addConnection($configConnection);
             break;
     }
     $this->capsule->setAsGlobal();
     $this->capsule->bootEloquent();
 }
Esempio n. 16
0
 /**
  * Build console entry point
  * @param array|null $services
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public static function init(array $services = null)
 {
     self::$Properties = new Properties();
     self::$Input = new Input();
     self::$Output = new Output();
     // establish database link
     if (Obj::isArray(self::$Properties->get('database')) && (isset($services['Database']) && $services['Database'] === true || $services === null)) {
         self::$Database = new Capsule();
         self::$Database->addConnection(self::$Properties->get('database'));
         // Make this Capsule instance available globally via static methods... (optional)
         self::$Database->setAsGlobal();
         // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
         self::$Database->bootEloquent();
     }
 }
Esempio n. 17
0
 public function __construct()
 {
     $config = Tempest::get()->config->get('db');
     if (!empty($config)) {
         $config = array_merge(array('driver' => 'mysql', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci'), $config);
         $connection = $this->parseConnectionString(ObjectUtil::getDeepValue($config, 'connection'));
         $connection = array_merge($config, $connection);
         $this->_capsule = new Manager();
         $this->_capsule->addConnection($connection);
         $this->_capsule->setAsGlobal();
         $this->_capsule->bootEloquent();
     } else {
         throw new Exception('No database connection details were provided by the application.');
     }
 }
    public function setUp()
    {
        $this->capsule = new \Illuminate\Database\Capsule\Manager();
        $this->capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
        $this->capsule->setAsGlobal();
        $this->capsule->bootEloquent();
        $ddl = <<<SQL
CREATE TABLE `sessions` (
  `id` varchar(255) NOT NULL UNIQUE,
  `payload` text NOT NULL,
  `last_activity` int(11) NOT NULL
)
SQL;
        $this->capsule->getConnection()->getPdo()->exec($ddl);
    }
Esempio n. 19
0
 public function __construct(array $connections)
 {
     $useEloquent = true;
     $fetchMode = null;
     $defaultConnName = null;
     $capsule = new Capsule();
     foreach ($connections as $name => $conn) {
         if (!$useEloquent && isset($conn['eloquent'])) {
             $useEloquent = true;
         }
         if ($fetchMode === null && isset($conn['fetch_mode']) && !empty($conn['fetch_mode'])) {
             $fetchMode = $conn['fetch_mode'];
         }
         if ($defaultConnName === null && isset($conn['default']) && $conn['default'] === true) {
             $defaultConnName = $name;
         }
         $capsule->addConnection($this->normaliseConfigKeys($conn), $name);
     }
     // Set the Capsule configuration options
     $config = $capsule->getContainer()->make('config');
     $config['database.fetch'] = $fetchMode ?: PDO::FETCH_ASSOC;
     $config['database.default'] = $defaultConnName ?: 'default';
     $capsule->getContainer()->instance('config', $config);
     // If the users are using eloquent, lets boot it
     if ($useEloquent) {
         $capsule->bootEloquent();
     }
     $capsule->setAsGlobal();
     $this->capsule = $capsule;
 }
Esempio n. 20
0
 public function setUp()
 {
     parent::setUp();
     Eloquent::unguard();
     $this->faker = Faker\Factory::create();
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->bootEloquent();
     $db->setAsGlobal();
     $this->schema()->create('users', function ($table) {
         $table->increments('id');
         $table->string('email');
         $table->string('name');
         $table->string('billing_id')->nullable();
         $table->text('billing_cards')->nullable();
         $table->text('billing_discounts')->nullable();
         $table->tinyInteger('billing_active')->default(0);
         $table->string('billing_subscription')->nullable();
         $table->tinyInteger('billing_free')->default(0);
         $table->string('billing_plan', 25)->nullable();
         $table->integer('billing_amount')->default(0);
         $table->string('billing_interval')->nullable();
         $table->integer('billing_quantity')->default(0);
         $table->string('billing_card')->nullable();
         $table->timestamp('billing_trial_ends_at')->nullable();
         $table->timestamp('billing_subscription_ends_at')->nullable();
         $table->text('billing_subscription_discounts')->nullable();
         $table->timestamps();
     });
 }
Esempio n. 21
0
 protected function setUpDatabase()
 {
     $database = new DB();
     $database->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $database->bootEloquent();
     $database->setAsGlobal();
 }
 /**
  * Configure the database
  */
 private function configureDatabase()
 {
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
     $db->bootEloquent();
     $db->setAsGlobal();
 }
Esempio n. 23
0
 public static function createConn()
 {
     $capsule = new DB();
     $capsule->addConnection(parse_ini_file("./config/config.ini"));
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Esempio n. 24
0
 private function setUpInMemoryDatabase()
 {
     $capsule = new Capsule();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
 }
Esempio n. 25
0
 public function setUp()
 {
     Eloquent::unguard();
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->bootEloquent();
     $db->setAsGlobal();
     $this->schema()->create('users', function ($table) {
         $table->increments('id');
         $table->string('email');
         $table->string('name');
         $table->string('stripe_id')->nullable();
         $table->string('card_brand')->nullable();
         $table->string('card_last_four')->nullable();
         $table->timestamps();
     });
     $this->schema()->create('subscriptions', function ($table) {
         $table->increments('id');
         $table->integer('user_id');
         $table->string('name');
         $table->string('stripe_id');
         $table->string('stripe_plan');
         $table->integer('quantity');
         $table->timestamp('trial_ends_at')->nullable();
         $table->timestamp('ends_at')->nullable();
         $table->timestamps();
     });
 }
 public function setUp()
 {
     Eloquent::unguard();
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     $db->bootEloquent();
     $db->setAsGlobal();
     $this->schema()->create('users', function ($table) {
         $table->increments('id');
         $table->string('email');
         $table->string('first_name');
         $table->string('last_name');
         $table->timestamps();
     });
     $this->schema()->create('subscriptions', function ($table) {
         $table->increments('id');
         $table->string('subscription_id');
         $table->string('plan_id');
         $table->integer('user_id')->index()->unsigned();
         $table->integer('quantity')->default(1);
         $table->integer('last_four')->nullable();
         $table->timestamp('ends_at')->nullable();
         $table->timestamp('trial_ends_at')->nullable();
         $table->timestamp('next_billing_at')->nullable();
         $table->timestamps();
     });
     $this->schema()->create('addons', function ($table) {
         $table->increments('id');
         $table->integer('subscription_id')->index()->unsigned();
         $table->string('addon_id');
         $table->integer('quantity')->default(0);
         $table->timestamps();
     });
 }
Esempio n. 27
0
 /**
  * Create fake sqlite database connection
  */
 protected function setupDatabase()
 {
     $database = new DB();
     $database->addConnection(["driver" => "sqlite", "database" => ":memory:"]);
     // $database->bootEloquent();
     $database->setAsGlobal();
 }
 public function register()
 {
     $this->app->singleton('laravel.db', function ($app) {
         $config = $app['config'];
         // Get the default database from the configuration
         $default = $config['database.default'];
         // Create an capsule instance
         $capsule = new CapsuleManager($app);
         // Override the default value with the user's config value
         $config['database.default'] = $default;
         if (!isset($config['database.connections']) || empty($config['database.connections'])) {
             throw new ConfigurationException("Invalid database configuration");
         }
         $connections = $config['database.connections'];
         foreach ($connections as $name => $connectionConfig) {
             $capsule->addConnection($connectionConfig, $name);
         }
         $capsule->setAsGlobal();
         // Setup the Eloquent ORM...
         if ($config['eloquent.boot'] === true) {
             $capsule->bootEloquent();
         }
         return $capsule->getDatabaseManager();
     });
 }
 public static function setupBeforeClass()
 {
     $db = new DB();
     $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
     $db->setAsGlobal();
     $db->bootEloquent();
     $db->schema()->create('voucher_campaigns', function ($table) {
         $table->increments('id');
         $table->timestamps();
         $table->string('name');
         $table->string('brand');
         $table->string('urn')->unique();
         $table->integer('expiry_limit')->default('14');
         $table->boolean('is_active')->default('1');
     });
     $db->schema()->create('voucher_entries', function ($table) {
         $table->increments('id');
         $table->timestamps();
         $table->string('hash')->unique();
         $table->integer('campaign_id');
         $table->boolean('is_redeemed')->default('0');
         $table->datetime('redeemed_at')->default('0000-00-00 00:00:00');
         $table->boolean('is_expired')->default('0');
         $table->datetime('expired_at')->default('0000-00-00 00:00:00');
         $table->boolean('is_valid')->default('1');
     });
     parent::setupBeforeClass();
     static::$fm->seed(5, 'Fastwebmedia\\LaravelVouchering\\Models\\Campaign');
     static::$fm->seed(5, 'Fastwebmedia\\LaravelVouchering\\Models\\Voucher');
 }
Esempio n. 30
0
 public static function init()
 {
     $db = new DB();
     $db->addConnection(parse_ini_file('db.ini'));
     $db->setAsGlobal();
     $db->bootEloquent();
 }