/**
  * 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');
     });
 }
 /**
  * Make the database connection instance.
  *
  * @param  string  $name
  * @return \Illuminate\Database\Connection
  */
 protected function makeConnection($name)
 {
     $config = $this->getConfig($name);
     if (isset($this->extensions[$name])) {
         return call_user_func($this->extensions[$name], $config);
     }
     return $this->factory->make($config, $name);
 }
 /**
  * Get a database connection instance.
  *
  * @param  string  $name
  * @return Illuminate\Database\Connection
  */
 public function connection($name = null)
 {
     $name = $name ?: $this->getDefaultConnection();
     // If we haven't created this connection, we'll create it based on the config
     // provided in the application. Once we've created the connections we will
     // set the "fetch mode" for PDO which determines the query return types.
     if (!isset($this->connections[$name])) {
         $connection = $this->factory->make($this->getConfig($name));
         $this->connections[$name] = $this->prepare($connection);
     }
     return $this->connections[$name];
 }
Example #4
0
 protected function configureEnvironment()
 {
     $this->config = $this->app['config']->get("multi-tenant.{$this->tenant}");
     // set base url
     Url::set($this->hostname);
     // set database
     $this->app->singleton('flarum.db', function () {
         $factory = new ConnectionFactory($this->app);
         $connection = $factory->make(array_merge($this->app->make('flarum.config')['database'], array_get($this->config, 'database', [])));
         $connection->setEventDispatcher($this->app->make('Illuminate\\Contracts\\Events\\Dispatcher'));
         $connection->setFetchMode(PDO::FETCH_CLASS);
         return $connection;
     });
 }
 /**
  * Create a new connection instance with Postgresify's PostgresConnection.
  *
  * @param  string   $driver
  * @param  \PDO     $connection
  * @param  string   $database
  * @param  string   $prefix
  * @param  array    $config
  * @return \Illuminate\Database\Connection
  *
  * @throws \InvalidArgumentException
  */
 protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = [])
 {
     if ($this->container->bound($key = "db.connection.{$driver}")) {
         return $this->container->make($key, [$connection, $database, $prefix, $config]);
     }
     if ($driver === 'pgsql') {
         return new PostgresConnection($connection, $database, $prefix, $config);
     }
     return parent::createConnection($driver, $connection, $database, $prefix, $config);
 }
 /**
  * Create a new connection instance.
  *
  * @param  string  $driver
  * @param  PDO     $connection
  * @param  string  $database
  * @param  string  $tablePrefix
  * @return Illuminate\Database\Connection
  */
 protected function createConnection($driver, PDO $connection, $database, $tablePrefix = '', array $config = array())
 {
     switch ($driver) {
         case 'odbc':
             return new ODBCConnection($connection, $database, $tablePrefix);
         case 'firebird':
             return new FirebirdConnection($connection, $database, $tablePrefix);
     }
     return parent::createConnection($driver, $connection, $database, $tablePrefix, $config);
 }
 /**
  * {@inheritdoc}
  */
 protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
 {
     if ($this->container->bound($key = "db.connection.{$driver}")) {
         return $this->container->make($key, [$connection, $database, $prefix, $config]);
     }
     // Override pgsql connection
     if ($driver == 'pgsql') {
         return new PostgresConnection($connection, $database, $prefix, $config);
     }
     // use default behavior otherwise
     return parent::createConnection($driver, $connection, $database, $prefix, $config);
 }
Example #8
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());
     });
 }
Example #9
0
 /**
  * Make the database connection instance.
  *
  * @param  string  $name
  * @return \Illuminate\Database\Connection
  */
 protected function makeConnection($name)
 {
     $config = $this->getConfig($name);
     // First we will check by the connection name to see if an extension has been
     // registered specifically for that connection. If it has we will call the
     // Closure and pass it the config allowing it to resolve the connection.
     if (isset($this->extensions[$name])) {
         return call_user_func($this->extensions[$name], $config, $name);
     }
     $driver = $config['driver'];
     // Next we will check to see if an extension has been registered for a driver
     // and will call the Closure if so, which allows us to have a more generic
     // resolver for the drivers themselves which applies to all connections.
     if (isset($this->extensions[$driver])) {
         return call_user_func($this->extensions[$driver], $config, $name);
     }
     return $this->factory->make($config, $name);
 }
 /**
  * Create a new connection instance.
  *
  * @param  string   $driver
  * @param  \PDO     $connection
  * @param  string   $database
  * @param  string   $prefix
  * @param  array    $config
  * @return \Illuminate\Database\Connection
  *
  * @throws \InvalidArgumentException
  */
 protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
 {
     if (!app()->environment('testing')) {
         return parent::createConnection($driver, $connection, $database, $prefix, $config);
     }
     if ($this->container->bound($key = "db.connection.{$driver}")) {
         return $this->container->make($key, array($connection, $database, $prefix, $config));
     }
     switch ($driver) {
         case 'mysql':
             return new MySqlConnection($connection, $database, $prefix, $config);
         case 'pgsql':
             return new PostgresConnection($connection, $database, $prefix, $config);
         case 'sqlite':
             return new SQLiteConnection($connection, $database, $prefix, $config);
         case 'sqlsrv':
             return new SqlServerConnection($connection, $database, $prefix, $config);
     }
     throw new InvalidArgumentException("Unsupported driver [{$driver}]");
 }
 /**
  * @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;
 }
Example #12
0
 /**
  * Set the database connection.
  *
  * @param array $config
  * @return void
  */
 public function setConnection(array $config)
 {
     $connection = new ConnectionFactory($this->container);
     $db = new ConnectionResolver(array(null => $connection->make($config)));
     $this->setPresenceVerifier($db);
 }
 /**
  * Get a database connection as configured.
  *
  * @return \Illuminate\Database\Connection
  */
 public function connection()
 {
     $config = array('driver' => $this->getDatabaseDriver(), 'host' => $this->parser->get('db_host'), 'database' => $this->parser->get('db_name'), 'username' => $this->parser->get('db_username'), 'password' => $this->parser->get('db_password'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => $this->parser->get('db_prefix'));
     return $this->factory->make($config, 'auth-fluxbb');
 }
 /**
  * Get a database connection as configured.
  *
  * @return \Illuminate\Database\Connection
  */
 public function connection()
 {
     $config = array('driver' => 'mysql', 'host' => $this->parser->get('esoTalk.database.host'), 'database' => $this->parser->get('esoTalk.database.dbName'), 'username' => $this->parser->get('esoTalk.database.user'), 'password' => $this->parser->get('esoTalk.database.password'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => $this->parser->get('esoTalk.database.prefix'));
     return $this->factory->make($config, 'esotalk-auth');
 }
Example #15
-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);
         });
     }
 }