Repository navigation
Expand file tree
/
Copy pathDriverList.php
More file actions
102 lines (92 loc) · 2.85 KB
/
Copy pathDriverList.php
File metadata and controls
102 lines (92 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
* This file is part of the Stash package.
*
* (c) Robert Hafner <tedivm@tedivm.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Stash;
/**
* DriverList contains various functions used to organize Driver classes that are available in the system.
*
* @package Stash
* @author Robert Hafner <tedivm@tedivm.com>
*/
class DriverList
{
/**
* An array of possible cache storage data methods, with the driver class as the array value.
*
* @var array
*/
protected static $drivers = array('Apc' => '\Stash\Driver\Apc',
'BlackHole' => '\Stash\Driver\BlackHole',
'Composite' => '\Stash\Driver\Composite',
'Ephemeral' => '\Stash\Driver\Ephemeral',
'FileSystem' => '\Stash\Driver\FileSystem',
'Memcache' => '\Stash\Driver\Memcache',
'Redis' => '\Stash\Driver\Redis',
'SQLite' => '\Stash\Driver\Sqlite',
);
/**
* Returns a list of cache drivers that are also supported by this system.
*
* @return array Driver Name => Class Name
*/
public static function getAvailableDrivers()
{
$availableDrivers = array();
$allDrivers = self::getAllDrivers();
foreach ($allDrivers as $name => $class) {
if ($name == 'Composite') {
$availableDrivers[$name] = $class;
} else {
if ($class::isAvailable()) {
$availableDrivers[$name] = $class;
}
}
}
return $availableDrivers;
}
/**
* Returns a list of all registered cache drivers, regardless of system support.
*
* @return array Driver Name => Class Name
*/
public static function getAllDrivers()
{
$driverList = array();
foreach (self::$drivers as $name => $class) {
if (!class_exists($class) || !in_array('Stash\Interfaces\DriverInterface', class_implements($class))) {
continue;
}
$driverList[$name] = $class;
}
return $driverList;
}
/**
* Registers a new driver.
*
* @param string $name
* @param string $class
*/
public static function registerDriver($name, $class)
{
self::$drivers[$name] = $class;
}
/**
* Returns the driver class for a specific driver name.
*
* @param string $name
* @return bool
*/
public static function getDriverClass($name)
{
if (!isset(self::$drivers[$name])) {
return false;
}
return self::$drivers[$name];
}
}