Completed
Push — master ( 8f800b...a10bf5 )
by Biao
03:46
created

ConnectionFactory::createConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 5
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Hhxsv5\LaravelS\Illuminate\Database;
4
5
use Hhxsv5\LaravelS\Illuminate\Database\Connectors\CoroutineMySQLConnector;
6
use Illuminate\Database\Connectors\ConnectionFactory as IlluminateConnectionFactory;
7
8
class ConnectionFactory extends IlluminateConnectionFactory
9
{
10
    public function createConnector(array $config)
11
    {
12
        if (!isset($config['driver'])) {
13
            throw new \InvalidArgumentException('A driver must be specified.');
14
        }
15
16
        switch ($config['driver']) {
17
            case 'sw-co-mysql':
18
                return new CoroutineMySQLConnector();
19
        }
20
        return parent::createConnector($config);
21
    }
22
23
    protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
24
    {
25
        switch ($driver) {
26
            case 'sw-co-mysql':
27
                return new CoroutineMySQLConnection($connection, $database, $prefix, $config);
28
        }
29
        return parent::createConnection($driver, $connection, $database, $prefix, $config);
30
    }
31
}