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\SqlServerConnection; |
12
|
|
|
|
13
|
|
|
class ConnectionFactory extends Base |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Create a new connection instance. |
17
|
|
|
* |
18
|
|
|
* @param string $driver |
19
|
|
|
* @param \PDO|\Closure $connection |
20
|
|
|
* @param string $database |
21
|
|
|
* @param string $prefix |
22
|
|
|
* @param array $config |
23
|
|
|
* @return \Illuminate\Database\Connection |
24
|
|
|
* |
25
|
|
|
* @throws \InvalidArgumentException |
26
|
|
|
*/ |
27
|
68 |
|
protected function createConnection($driver, $connection, $database, $prefix = '', array $config = []) |
28
|
|
|
{ |
29
|
68 |
|
if ($resolver = Connection::getResolver($driver)) { |
30
|
|
|
return $resolver($connection, $database, $prefix, $config); // @codeCoverageIgnore |
31
|
|
|
} |
32
|
|
|
|
33
|
68 |
|
switch ($driver) { |
34
|
68 |
|
case 'mysql': |
35
|
17 |
|
return new MySqlConnection($connection, $database, $prefix, $config); |
36
|
51 |
|
case 'pgsql': |
37
|
17 |
|
return new PostgresConnection($connection, $database, $prefix, $config); |
38
|
34 |
|
case 'sqlite': |
39
|
17 |
|
return new SQLiteConnection($connection, $database, $prefix, $config); |
40
|
17 |
|
case 'sqlsrv': |
41
|
17 |
|
return new SqlServerConnection($connection, $database, $prefix, $config); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
throw new InvalidArgumentException("Unsupported driver [{$driver}]"); // @codeCoverageIgnore |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|