Completed
Push — master ( 46d273...229a5a )
by Mathieu
02:04
created

MasterSlavesDriver::getSchemaManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ez\DbLinker\Driver;
4
5
use Ez\DbLinker\Driver\Connection\MasterSlavesConnection;
6
7
trait MasterSlavesDriver
8
{
9
    use WrapperDriver;
10
11
    /**
12
     * Attempts to create a connection with the database.
13
     *
14
     * @param array       $params        All connection parameters passed by the user.
15
     * @param string|null $username      The username to use when connecting.
16
     * @param string|null $password      The password to use when connecting.
17
     * @param array       $driverOptions The driver options to use when connecting.
18
     *
19
     * @return \Doctrine\DBAL\Driver\Connection The database connection.
20
     */
21
    public function connect(Array $params, $username = null, $password = null, Array $driverOptions = []) {
22
        $driverKey = array_key_exists('driverClass', $params['master']) ? 'driverClass' : 'driver';
23
        $driverValue = $params['master'][$driverKey];
24
        $slaves = [];
25
        foreach ($params['slaves'] as $slaveParams) {
26
            $slaveParams[$driverKey] = $driverValue;
27
            $slaves[] = $slaveParams;
28
        }
29
        return new MasterSlavesConnection($params['master'], $slaves);
30
    }
31
}
32