public function register(Application $app)
 {
     $app['db.default'] = '';
     $app['db.container'] = $app->share(function ($app) {
         return new Container();
     });
     $app['db.factory'] = $app->share(function ($app) {
         return new ConnectionFactory($app['db.container']);
     });
     $app['db.resolver'] = $app->share(function ($app) {
         $resolver = new ConnectionResolver();
         $config = isset($app['app.config']['db']) ? $app['app.config']['db'] : array();
         if (isset($config['connections'])) {
             foreach ($config['connections'] as $name => $conn) {
                 $connection = $app['db.factory']->make($conn);
                 if (!$app['debug']) {
                     $connection->disableQueryLog();
                 }
                 $resolver->addConnection($name, $connection);
             }
         }
         if (isset($config['default'])) {
             $app['db.default'] = $config['default'];
         }
         $resolver->setDefaultConnection($app['db.default']);
         return $resolver;
     });
     $app['db'] = $app->share(function ($app) {
         return $app['db.resolver']->connection($app['db.default']);
     });
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('flarum.db', function () {
         $factory = new ConnectionFactory($this->app);
         $connection = $factory->make($this->app->make('flarum.config')['database']);
         $connection->setEventDispatcher($this->app->make('Illuminate\\Contracts\\Events\\Dispatcher'));
         $connection->setFetchMode(PDO::FETCH_CLASS);
         return $connection;
     });
     $this->app->alias('flarum.db', 'Illuminate\\Database\\ConnectionInterface');
     $this->app->singleton('Illuminate\\Database\\ConnectionResolverInterface', function () {
         $resolver = new ConnectionResolver(['flarum' => $this->app->make('flarum.db')]);
         $resolver->setDefaultConnection('flarum');
         return $resolver;
     });
     $this->app->alias('Illuminate\\Database\\ConnectionResolverInterface', 'db');
     if (Core::isInstalled()) {
         $this->app->booting(function () {
             $resolver = $this->app->make('Illuminate\\Database\\ConnectionResolverInterface');
             Model::setConnectionResolver($resolver);
             Model::setEventDispatcher($this->app->make('events'));
         });
     }
     $this->app->singleton('Flarum\\Migrations\\MigrationRepositoryInterface', function ($app) {
         return new DatabaseMigrationRepository($app['db'], 'migrations');
     });
 }
Пример #3
0
 public function getResolver()
 {
     $res = new ConnectionResolver();
     $res->addConnection('tests', self::$connection);
     $res->setDefaultConnection('tests');
     return $res;
 }
Пример #4
0
 private function setConnectionResolver()
 {
     if ($this->checkTablesExists() && is_null(Model::getConnectionResolver())) {
         $res = new ConnectionResolver();
         DB::pretend(function ($db) use($res) {
             $res->addConnection(config('database.default'), $db);
             $res->setDefaultConnection(config('database.default'));
         });
         Model::setConnectionResolver($res);
     }
 }
 public function ignite()
 {
     $this->app->bindShared('db.connections', function ($app) {
         $resolver = new ConnectionResolver(['wpdb' => new WpdbConnection()]);
         $resolver->setDefaultConnection('wpdb');
         return $resolver;
     });
     $this->app->bindShared('db', function ($app) {
         return $app['db.connections']->connection();
     });
     Model::setConnectionResolver($this->app['db.connections']);
 }
 /**
  * Register database services
  * 
  * @param  PimpleContainer $di Container
  */
 public function register(PimpleContainer $di)
 {
     $params = $this->databaseParams;
     $di['dbConnection'] = function () use($params, $di) {
         $capsule = $di['db'];
         return $capsule->getConnection();
     };
     $di['dbConnectionResolver'] = function () use($params, $di) {
         $connection = $di['dbConnection'];
         $resolver = new ConnectionResolver(['default' => $connection]);
         $resolver->setDefaultConnection('default');
         return $resolver;
     };
     $di['dbMigrationRepository'] = function () use($params, $di) {
         $resolver = $di['dbConnectionResolver'];
         $repository = new DatabaseMigrationRepository($resolver, 'migrations');
         return $repository;
     };
     $di['dbMigrator'] = function () use($params, $di) {
         class_alias(Schema::class, 'Schema');
         Schema::setContainer($di);
         $resolver = $di['dbConnectionResolver'];
         $repository = $di['dbMigrationRepository'];
         $filesystem = new Filesystem();
         $migrator = new Migrator($repository, $resolver, $filesystem);
         return $migrator;
     };
     $di['db'] = function () use($params, $di) {
         class_alias(DB::class, 'DB');
         DB::setContainer($di);
         $capsule = new Capsule();
         $capsule->setEventDispatcher(new Dispatcher(new Container()));
         $capsule->setAsGlobal();
         $capsule->bootEloquent();
         $capsule->addConnection($params);
         if (class_exists(MongoDbConnection::class)) {
             $capsule->getDatabaseManager()->extend('mongodb', function ($config) {
                 return new MongoDbConnection($config);
             });
         }
         return $capsule;
     };
     $di['dbManager'] = function () use($params, $di) {
         $dbCapsule = $di['db'];
         return $dbCapsule->getDatabaseManager();
     };
     $di['db'];
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function register()
 {
     $this->app->singleton('flarum.db', function () {
         $factory = new ConnectionFactory($this->app);
         $connection = $factory->make($this->app->config('database'));
         $connection->setEventDispatcher($this->app->make('Illuminate\\Contracts\\Events\\Dispatcher'));
         $connection->setFetchMode(PDO::FETCH_CLASS);
         return $connection;
     });
     $this->app->alias('flarum.db', 'Illuminate\\Database\\ConnectionInterface');
     $this->app->singleton('Illuminate\\Database\\ConnectionResolverInterface', function () {
         $resolver = new ConnectionResolver(['flarum' => $this->app->make('flarum.db')]);
         $resolver->setDefaultConnection('flarum');
         return $resolver;
     });
     $this->app->alias('Illuminate\\Database\\ConnectionResolverInterface', 'db');
     $this->app->singleton('Flarum\\Database\\MigrationRepositoryInterface', function ($app) {
         return new DatabaseMigrationRepository($app['db'], 'migrations');
     });
     $this->app->bind(MigrationCreator::class, function (Application $app) {
         return new MigrationCreator($app->make('Illuminate\\Filesystem\\Filesystem'), $app->basePath());
     });
 }
 /**
  * @param array $dbConfig
  *
  * @return \Illuminate\Database\ConnectionResolver
  */
 protected function buildConnection(array $dbConfig)
 {
     $connFactory = new ConnectionFactory($this->container);
     $conn = $connFactory->make($dbConfig);
     $resolver = new ConnectionResolver();
     $resolver->addConnection('default', $conn);
     $resolver->setDefaultConnection('default');
     return $resolver;
 }
Пример #9
0
 /**
  * Build a fixture instance.
  *
  * @return void
  */
 protected function buildFixture()
 {
     if ($this->fixture) {
         return;
     }
     $this->db = $this->buildDB();
     $str = new Str();
     $this->fixture = Fixture::getInstance();
     $repository = new Eloquent($this->db, $str);
     $this->fixture->setDriver($repository);
     // Bootstrap Eloquent
     $sqliteConnection = new SQLiteConnection($this->db);
     $resolver = new ConnectionResolver(array('sqlite' => $sqliteConnection));
     $resolver->setDefaultConnection('sqlite');
     Model::setConnectionResolver($resolver);
 }
Пример #10
-1
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('Illuminate\\Database\\ConnectionInterface', function () {
         $factory = new ConnectionFactory($this->app);
         $connection = $factory->make($this->app['config']->get('fluxbb.database'));
         $connection->setEventDispatcher($this->app->make('Illuminate\\Contracts\\Events\\Dispatcher'));
         $connection->setFetchMode(PDO::FETCH_CLASS);
         return $connection;
     });
     $this->app->singleton('Illuminate\\Database\\ConnectionResolverInterface', function () {
         $resolver = new ConnectionResolver(['fluxbb' => $this->app->make('Illuminate\\Database\\ConnectionInterface')]);
         $resolver->setDefaultConnection('fluxbb');
         return $resolver;
     });
     if (Core::isInstalled()) {
         $this->app->booting(function () {
             $resolver = $this->app->make('Illuminate\\Database\\ConnectionResolverInterface');
             Model::setConnectionResolver($resolver);
         });
     }
 }