2020-05-08 10:54:09 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Banker
|
|
|
|
*
|
|
|
|
* A Caching library implementing psr/cache (PSR 6) and psr/simple-cache (PSR 16)
|
|
|
|
*
|
2021-11-30 11:56:15 -05:00
|
|
|
* PHP version 8+
|
2020-05-08 10:54:09 -04:00
|
|
|
*
|
|
|
|
* @package Banker
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2021-02-05 17:05:56 -05:00
|
|
|
* @copyright 2016 - 2021 Timothy J. Warren
|
2020-05-08 10:54:09 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2021-11-30 11:56:15 -05:00
|
|
|
* @version 5.0.0
|
2020-05-08 10:54:09 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/banker
|
|
|
|
*/
|
|
|
|
namespace Aviat\Banker;
|
|
|
|
|
2021-02-19 12:18:38 -05:00
|
|
|
use Aviat\Banker\Driver\AbstractDriver;
|
2020-05-08 10:54:09 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private trait for shared driver-related functionality
|
|
|
|
*/
|
|
|
|
trait _Driver {
|
2021-02-05 13:26:01 -05:00
|
|
|
use KeyValidateTrait;
|
|
|
|
|
2020-05-08 10:54:09 -04:00
|
|
|
/**
|
|
|
|
* Driver class for handling the chosen caching backend
|
|
|
|
*
|
2021-02-19 12:18:38 -05:00
|
|
|
* @var AbstractDriver
|
2020-05-08 10:54:09 -04:00
|
|
|
*/
|
2021-02-19 12:18:38 -05:00
|
|
|
private AbstractDriver $driver;
|
2020-05-08 10:54:09 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate the appropriate cache backend based on the config
|
|
|
|
*
|
|
|
|
* @param array $driverConfig
|
2021-02-19 12:18:38 -05:00
|
|
|
* @return AbstractDriver
|
2020-05-08 10:54:09 -04:00
|
|
|
*/
|
2021-02-19 12:18:38 -05:00
|
|
|
protected function loadDriver(array $driverConfig = []): AbstractDriver
|
2020-05-08 10:54:09 -04:00
|
|
|
{
|
|
|
|
$driver = ucfirst(strtolower($driverConfig['driver'] ?? 'null'));
|
|
|
|
$class = __NAMESPACE__ . "\\Driver\\${driver}Driver";
|
|
|
|
|
|
|
|
$driverConfig['connection'] = $driverConfig['connection'] ?? [];
|
|
|
|
$driverConfig['options'] = $driverConfig['options'] ?? [];
|
|
|
|
|
|
|
|
return new $class($driverConfig['connection'], $driverConfig['options']);
|
|
|
|
}
|
|
|
|
}
|