45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\framework\Database\Connectors;
|
|
|
|
|
|
use app\framework\Database\MySqlConnection;
|
|
use Illuminate\Database\PostgresConnection;
|
|
use Illuminate\Database\SQLiteConnection;
|
|
use Illuminate\Database\SqlServerConnection;
|
|
|
|
class ConnectionFactory extends \Illuminate\Database\Connectors\ConnectionFactory
|
|
{
|
|
/**
|
|
* Create a new connection instance.
|
|
*
|
|
* @param string $driver
|
|
* @param \PDO|\Closure $connection
|
|
* @param string $database
|
|
* @param string $prefix
|
|
* @param array $config
|
|
* @return \Illuminate\Database\Connection
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
*/
|
|
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]);
|
|
}
|
|
|
|
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]");
|
|
}
|
|
} |