banker/src/_Driver.php

49 lines
1.3 KiB
PHP
Raw Normal View History

<?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+
*
* @package Banker
* @author Timothy J. Warren <tim@timshomepage.net>
2021-02-05 17:05:56 -05:00
* @copyright 2016 - 2021 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2021-11-30 11:56:15 -05:00
* @version 5.0.0
* @link https://git.timshomepage.net/timw4mail/banker
*/
namespace Aviat\Banker;
2021-02-19 12:18:38 -05:00
use Aviat\Banker\Driver\AbstractDriver;
/**
* Private trait for shared driver-related functionality
*/
trait _Driver {
use KeyValidateTrait;
/**
* Driver class for handling the chosen caching backend
*
2021-02-19 12:18:38 -05:00
* @var AbstractDriver
*/
2021-02-19 12:18:38 -05:00
private AbstractDriver $driver;
/**
* Instantiate the appropriate cache backend based on the config
*
* @param array $driverConfig
2021-02-19 12:18:38 -05:00
* @return AbstractDriver
*/
2021-02-19 12:18:38 -05:00
protected function loadDriver(array $driverConfig = []): AbstractDriver
{
$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']);
}
}