Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Config | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
hasLogger | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasOptions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
hasConnections | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Projom\Storage\Engine\Driver; |
6 | |
7 | use Projom\Storage\Engine\Driver\Driver; |
8 | use Projom\Storage\Engine\Driver\Connection\Config as ConnectionConfig; |
9 | use Psr\Log\LoggerInterface; |
10 | |
11 | /** |
12 | * Driver configuration. |
13 | */ |
14 | class Config |
15 | { |
16 | public readonly null|Driver $driver; |
17 | public readonly array $options; |
18 | public readonly null|LoggerInterface $logger; |
19 | public array $connections = []; |
20 | |
21 | public function __construct(array $config) |
22 | { |
23 | $this->driver = Driver::tryFrom($config['driver'] ?? ''); |
24 | $this->options = $config['options'] ?? []; |
25 | $this->logger = $config['logger'] ?? null; |
26 | |
27 | $connections = $config['connections'] ?? []; |
28 | foreach ($connections as $connection) |
29 | $this->connections[] = new ConnectionConfig($connection); |
30 | } |
31 | |
32 | public function hasLogger(): bool |
33 | { |
34 | return $this->logger !== null; |
35 | } |
36 | |
37 | public function hasOptions(): bool |
38 | { |
39 | return $this->options ? true : false; |
40 | } |
41 | |
42 | public function hasConnections(): bool |
43 | { |
44 | return $this->connections ? true : false; |
45 | } |
46 | } |