Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
5 / 5 |
_Driver | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
loadDriver | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
1 | <?php declare(strict_types=1); |
2 | /** |
3 | * Banker |
4 | * |
5 | * A Caching library implementing psr/cache (PSR 6) and psr/simple-cache (PSR 16) |
6 | * |
7 | * PHP version 7.4 |
8 | * |
9 | * @package Banker |
10 | * @author Timothy J. Warren <tim@timshomepage.net> |
11 | * @copyright 2016 - 2020 Timothy J. Warren |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
13 | * @version 3.1.0 |
14 | * @link https://git.timshomepage.net/timw4mail/banker |
15 | */ |
16 | namespace Aviat\Banker; |
17 | |
18 | use Aviat\Banker\Driver\DriverInterface; |
19 | use Aviat\Banker\Exception\InvalidArgumentException; |
20 | |
21 | /** |
22 | * Private trait for shared driver-related functionality |
23 | */ |
24 | trait _Driver { |
25 | use KeyValidateTrait; |
26 | |
27 | /** |
28 | * Driver class for handling the chosen caching backend |
29 | * |
30 | * @var DriverInterface |
31 | */ |
32 | private DriverInterface $driver; |
33 | |
34 | /** |
35 | * Instantiate the appropriate cache backend based on the config |
36 | * |
37 | * @param array $driverConfig |
38 | * @return DriverInterface |
39 | */ |
40 | protected function loadDriver(array $driverConfig = []): DriverInterface |
41 | { |
42 | $driver = ucfirst(strtolower($driverConfig['driver'] ?? 'null')); |
43 | $class = __NAMESPACE__ . "\\Driver\\${driver}Driver"; |
44 | |
45 | $driverConfig['connection'] = $driverConfig['connection'] ?? []; |
46 | $driverConfig['options'] = $driverConfig['options'] ?? []; |
47 | |
48 | return new $class($driverConfig['connection'], $driverConfig['options']); |
49 | } |
50 | } |