1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Staudenmeir\LaravelCte\Connectors; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Connection; |
6
|
|
|
use Illuminate\Database\Connectors\ConnectionFactory as Base; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Staudenmeir\LaravelCte\Connections\MySqlConnection; |
9
|
|
|
use Staudenmeir\LaravelCte\Connections\PostgresConnection; |
10
|
|
|
use Staudenmeir\LaravelCte\Connections\SQLiteConnection; |
11
|
|
|
use Staudenmeir\LaravelCte\Connections\SingleStoreConnection; |
12
|
|
|
use Staudenmeir\LaravelCte\Connections\SqlServerConnection; |
13
|
|
|
|
14
|
|
|
class ConnectionFactory extends Base |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Create a new connection instance. |
18
|
|
|
* |
19
|
|
|
* @param string $driver |
20
|
|
|
* @param \PDO|\Closure $connection |
21
|
|
|
* @param string $database |
22
|
|
|
* @param string $prefix |
23
|
|
|
* @param array $config |
24
|
|
|
* @return \Illuminate\Database\Connection |
25
|
|
|
* |
26
|
|
|
* @throws \InvalidArgumentException |
27
|
132 |
|
*/ |
28
|
|
|
protected function createConnection($driver, $connection, $database, $prefix = '', array $config = []) |
29
|
132 |
|
{ |
30
|
|
|
if ($driver != 'singlestore' && $resolver = Connection::getResolver($driver)) { |
31
|
|
|
return $resolver($connection, $database, $prefix, $config); // @codeCoverageIgnore |
32
|
|
|
} |
33
|
|
|
|
34
|
132 |
|
switch ($driver) { |
35
|
49 |
|
case 'mysql': |
36
|
83 |
|
return new MySqlConnection($connection, $database, $prefix, $config); |
37
|
31 |
|
case 'pgsql': |
38
|
52 |
|
return new PostgresConnection($connection, $database, $prefix, $config); |
39
|
27 |
|
case 'sqlite': |
40
|
25 |
|
return new SQLiteConnection($connection, $database, $prefix, $config); |
41
|
25 |
|
case 'sqlsrv': |
42
|
|
|
return new SqlServerConnection($connection, $database, $prefix, $config); |
43
|
|
|
case 'singlestore': |
44
|
|
|
return new SingleStoreConnection($connection, $database, $prefix, $config); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
throw new InvalidArgumentException("Unsupported driver [{$driver}]"); // @codeCoverageIgnore |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|