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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Cache\Storage;
use Zend\Cache\Exception\RuntimeException;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;
/**
* Plugin manager implementation for cache storage adapters
*
* Enforces that adapters retrieved are instances of
* StorageInterface. Additionally, it registers a number of default
* adapters available.
*/
class AdapterPluginManager extends AbstractPluginManager
{
protected $aliases = [
'apc' => Adapter\Apc::class,
'Apc' => Adapter\Apc::class,
'APC' => Adapter\Apc::class,
'apcu' => Adapter\Apcu::class,
'ApcU' => Adapter\Apcu::class,
'Apcu' => Adapter\Apcu::class,
'APCu' => Adapter\Apcu::class,
'black_hole' => Adapter\BlackHole::class,
'blackhole' => Adapter\BlackHole::class,
'blackHole' => Adapter\BlackHole::class,
'BlackHole' => Adapter\BlackHole::class,
'dba' => Adapter\Dba::class,
'Dba' => Adapter\Dba::class,
'DBA' => Adapter\Dba::class,
'ext_mongo_db' => Adapter\ExtMongoDb::class,
'extmongodb' => Adapter\ExtMongoDb::class,
'ExtMongoDb' => Adapter\ExtMongoDb::class,
'ExtMongoDB' => Adapter\ExtMongoDb::class,
'extMongoDb' => Adapter\ExtMongoDb::class,
'extMongoDB' => Adapter\ExtMongoDb::class,
'filesystem' => Adapter\Filesystem::class,
'Filesystem' => Adapter\Filesystem::class,
'memcache' => Adapter\Memcache::class,
'Memcache' => Adapter\Memcache::class,
'memcached' => Adapter\Memcached::class,
'Memcached' => Adapter\Memcached::class,
'memory' => Adapter\Memory::class,
'Memory' => Adapter\Memory::class,
'mongo_db' => Adapter\MongoDb::class,
'mongodb' => Adapter\MongoDb::class,
'MongoDb' => Adapter\MongoDb::class,
'MongoDB' => Adapter\MongoDb::class,
'mongoDb' => Adapter\MongoDb::class,
'mongoDB' => Adapter\MongoDb::class,
'redis' => Adapter\Redis::class,
'Redis' => Adapter\Redis::class,
'session' => Adapter\Session::class,
'Session' => Adapter\Session::class,
'xcache' => Adapter\XCache::class,
'xCache' => Adapter\XCache::class,
'Xcache' => Adapter\XCache::class,
'XCache' => Adapter\XCache::class,
'win_cache' => Adapter\WinCache::class,
'wincache' => Adapter\WinCache::class,
'winCache' => Adapter\WinCache::class,
'WinCache' => Adapter\WinCache::class,
'zend_server_disk' => Adapter\ZendServerDisk::class,
'zendserverdisk' => Adapter\ZendServerDisk::class,
'zendServerDisk' => Adapter\ZendServerDisk::class,
'ZendServerDisk' => Adapter\ZendServerDisk::class,
'zend_server_shm' => Adapter\ZendServerShm::class,
'zendservershm' => Adapter\ZendServerShm::class,
'zendServerShm' => Adapter\ZendServerShm::class,
'zendServerSHM' => Adapter\ZendServerShm::class,
'ZendServerShm' => Adapter\ZendServerShm::class,
'ZendServerSHM' => Adapter\ZendServerShm::class,
];
protected $factories = [
Adapter\Apc::class => InvokableFactory::class,
Adapter\Apcu::class => InvokableFactory::class,
Adapter\BlackHole::class => InvokableFactory::class,
Adapter\Dba::class => InvokableFactory::class,
Adapter\ExtMongoDb::class => InvokableFactory::class,
Adapter\Filesystem::class => InvokableFactory::class,
Adapter\Memcache::class => InvokableFactory::class,
Adapter\Memcached::class => InvokableFactory::class,
Adapter\Memory::class => InvokableFactory::class,
Adapter\MongoDb::class => InvokableFactory::class,
Adapter\Redis::class => InvokableFactory::class,
Adapter\Session::class => InvokableFactory::class,
Adapter\WinCache::class => InvokableFactory::class,
Adapter\XCache::class => InvokableFactory::class,
Adapter\ZendServerDisk::class => InvokableFactory::class,
Adapter\ZendServerShm::class => InvokableFactory::class,
// v2 normalized FQCNs
'zendcachestorageadapterapc' => InvokableFactory::class,
'zendcachestorageadapterapcu' => InvokableFactory::class,
'zendcachestorageadapterblackhole' => InvokableFactory::class,
'zendcachestorageadapterdba' => InvokableFactory::class,
'zendcachestorageadapterextmongodb' => InvokableFactory::class,
'zendcachestorageadapterfilesystem' => InvokableFactory::class,
'zendcachestorageadaptermemcache' => InvokableFactory::class,
'zendcachestorageadaptermemcached' => InvokableFactory::class,
'zendcachestorageadaptermemory' => InvokableFactory::class,
'zendcachestorageadaptermongodb' => InvokableFactory::class,
'zendcachestorageadapterredis' => InvokableFactory::class,
'zendcachestorageadaptersession' => InvokableFactory::class,
'zendcachestorageadapterwincache' => InvokableFactory::class,
'zendcachestorageadapterxcache' => InvokableFactory::class,
'zendcachestorageadapterzendserverdisk' => InvokableFactory::class,
'zendcachestorageadapterzendservershm' => InvokableFactory::class,
];
/**
* Do not share by default (v3)
*
* @var array
*/
protected $sharedByDefault = false;
/**
* Don't share by default (v2)
*
* @var boolean
*/
protected $shareByDefault = false;
/**
* @var string
*/
protected $instanceOf = StorageInterface::class;
/**
* Validate the plugin is of the expected type (v3).
*
* Validates against `$instanceOf`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validate($instance)
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'%s can only create instances of %s; %s is invalid',
get_class($this),
$this->instanceOf,
(is_object($instance) ? get_class($instance) : gettype($instance))
));
}
}
/**
* Validate the plugin is of the expected type (v2).
*
* Proxies to `validate()`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validatePlugin($instance)
{
try {
$this->validate($instance);
} catch (InvalidServiceException $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
}
}