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)
|
|
|
|
*
|
|
|
|
* PHP version 7.4
|
|
|
|
*
|
|
|
|
* @package Banker
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2016 - 2020 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-05-08 12:30:43 -04:00
|
|
|
* @version 3.1.0
|
2020-05-08 10:54:09 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/banker
|
|
|
|
*/
|
|
|
|
namespace Aviat\Banker;
|
|
|
|
|
|
|
|
use Aviat\Banker\Driver\DriverInterface;
|
|
|
|
use Aviat\Banker\Exception\InvalidArgumentException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @var DriverInterface
|
|
|
|
*/
|
|
|
|
private DriverInterface $driver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate the appropriate cache backend based on the config
|
|
|
|
*
|
|
|
|
* @param array $driverConfig
|
|
|
|
* @return DriverInterface
|
|
|
|
*/
|
|
|
|
protected function loadDriver(array $driverConfig = []): DriverInterface
|
|
|
|
{
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
}
|