Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
_Driver | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
loadDriver | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
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 8+ |
8 | * |
9 | * @package Banker |
10 | * @author Timothy J. Warren <tim@timshomepage.net> |
11 | * @copyright 2016 - 2023 Timothy J. Warren |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
13 | * @version 4.1.0 |
14 | * @link https://git.timshomepage.net/timw4mail/banker |
15 | */ |
16 | namespace Aviat\Banker; |
17 | |
18 | use Aviat\Banker\Driver\AbstractDriver; |
19 | |
20 | /** |
21 | * Private trait for shared driver-related functionality |
22 | */ |
23 | trait _Driver { |
24 | /** |
25 | * Driver class for handling the chosen caching backend |
26 | */ |
27 | private AbstractDriver $driver; |
28 | |
29 | /** |
30 | * Instantiate the appropriate cache backend based on the config |
31 | */ |
32 | protected function loadDriver(array $driverConfig = []): AbstractDriver |
33 | { |
34 | $driver = ucfirst(strtolower($driverConfig['driver'] ?? 'null')); |
35 | $class = __NAMESPACE__ . "\\Driver\\{$driver}Driver"; |
36 | |
37 | $driverConfig['connection'] = $driverConfig['connection'] ?? []; |
38 | $driverConfig['options'] = $driverConfig['options'] ?? []; |
39 | |
40 | // @phpstan-ignore-next-line |
41 | return new $class($driverConfig['connection'], $driverConfig['options']); |
42 | } |
43 | } |