Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.12% |
16 / 17 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ConnectionFactory | |
94.12% |
16 / 17 |
|
66.67% |
2 / 3 |
6.01 | |
0.00% |
0 / 1 |
create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
PDOConnections | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 | |||
PDOConnection | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Projom\Storage\Engine\Driver\Connection; |
6 | |
7 | use Projom\Storage\Engine\Driver\Connection\Config; |
8 | |
9 | class ConnectionFactory |
10 | { |
11 | const DEFAULT_PDO_ATTRIBUTES = [ |
12 | \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, |
13 | \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION |
14 | ]; |
15 | |
16 | public static function create(): ConnectionFactory |
17 | { |
18 | return new ConnectionFactory(); |
19 | } |
20 | |
21 | public function PDOConnections(array $connectionConfigurations): array |
22 | { |
23 | $PDOConnections = []; |
24 | foreach ($connectionConfigurations as $index => $config) { |
25 | |
26 | if (!$config->hasDSN()) |
27 | $config->dsn = DSN::MySQL($config); |
28 | |
29 | if (!$config->hasName()) |
30 | $config->name = $index + 1; |
31 | |
32 | $PDOConnections[] = $this->PDOConnection($config); |
33 | } |
34 | |
35 | return $PDOConnections; |
36 | } |
37 | |
38 | public function PDOConnection(Config $config): PDOConnection |
39 | { |
40 | $connection = PDOConnection::create( |
41 | $config->name, |
42 | $config->dsn, |
43 | $config->username, |
44 | $config->password, |
45 | $config->options |
46 | ); |
47 | return $connection; |
48 | } |
49 | } |