Completed
Push — V6 ( 3487d5...56e1e4 )
by Georges
02:48
created

ActOnAll::setEventManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 1
b 0
f 1
1
<?php
2
namespace phpFastCache\Helper;
3
4
use phpFastCache\CacheManager;
5
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
6
use phpFastCache\EventManager;
7
use Psr\Cache\CacheItemInterface;
8
9
/**
10
 * Class ActOnAll
11
 * @package phpFastCache\Helper
12
 */
13
class ActOnAll implements ExtendedCacheItemPoolInterface
14
{
15
    /**
16
     * @var array|\phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface[]
17
     */
18
    protected $instances = [];
19
20
    /**
21
     * ActOnAll constructor.
22
     */
23
    public function __construct()
24
    {
25
        $this->instances =& CacheManager::getInternalInstances();
26
    }
27
28
    /**
29
     * @return \Closure
30
     */
31
    protected function getGenericCallback()
32
    {
33
        return function($method, $args){
34
            $getterMethod = (strpos($method, 'get') === 0);
35
            $return = false;
36
37
            if($getterMethod){
38
                $return = [];
39
            }
40
41
            foreach ($this->instances as $instance)
42
            {
43
                $reflectionMethod = new \ReflectionMethod(get_class($instance), $method);
44
                if($getterMethod){
45
                    $return[ $instance->getDriverName() ] = $reflectionMethod->invokeArgs($instance, $args);
46
                }else{
47
                    $result = $reflectionMethod->invokeArgs($instance, $args);
48
                    if($result !== false){
49
                        $return = $result;
50
                    }
51
                }
52
            }
53
            return $return;
54
        };
55
    }
56
57
58
    /**
59
     * @param string $key
60
     * @return mixed
61
     */
62
    public function hasItem($key)
63
    {
64
        $callback = $this->getGenericCallback();
65
        return $callback(__FUNCTION__, func_get_args());
66
    }
67
68
    /**
69
     * @return mixed
70
     */
71
    public function clear()
72
    {
73
        $callback = $this->getGenericCallback();
74
        return $callback(__FUNCTION__, func_get_args());
75
    }
76
77
    /**
78
     * @param string $key
79
     * @return mixed
80
     */
81
    public function deleteItem($key)
82
    {
83
        $callback = $this->getGenericCallback();
84
        return $callback(__FUNCTION__, func_get_args());
85
    }
86
87
    /**
88
     * @param array $keys
89
     * @return mixed
90
     */
91
    public function deleteItems(array $keys)
92
    {
93
        $callback = $this->getGenericCallback();
94
        return $callback(__FUNCTION__, func_get_args());
95
    }
96
97
    /**
98
     * @param \Psr\Cache\CacheItemInterface $item
99
     * @return mixed
100
     */
101
    public function save(CacheItemInterface $item)
102
    {
103
        $callback = $this->getGenericCallback();
104
        return $callback(__FUNCTION__, func_get_args());
105
    }
106
107
    /**
108
     * @param \Psr\Cache\CacheItemInterface $item
109
     * @return mixed
110
     */
111
    public function saveDeferred(CacheItemInterface $item)
112
    {
113
        $callback = $this->getGenericCallback();
114
        return $callback(__FUNCTION__, func_get_args());
115
    }
116
117
    /**
118
     * @return mixed
119
     */
120
    public function commit()
121
    {
122
        $callback = $this->getGenericCallback();
123
        return $callback(__FUNCTION__, func_get_args());
124
    }
125
126
    /**
127
     * @return mixed
128
     */
129
    public function getConfig()
130
    {
131
        $callback = $this->getGenericCallback();
132
        return $callback(__FUNCTION__, func_get_args());
133
    }
134
135
    /**
136
     * @return mixed
137
     */
138
    public function getDriverName()
139
    {
140
        $callback = $this->getGenericCallback();
141
        return $callback(__FUNCTION__, func_get_args());
142
    }
143
144
    /**
145
     * @param string $key
146
     * @return mixed
147
     */
148
    public function getItem($key)
149
    {
150
        $callback = $this->getGenericCallback();
151
        return $callback(__FUNCTION__, func_get_args());
152
    }
153
154
    /**
155
     * @param array $keys
156
     * @return mixed
157
     */
158
    public function getItems(array $keys = [])
159
    {
160
        $callback = $this->getGenericCallback();
161
        return $callback(__FUNCTION__, func_get_args());
162
    }
163
164
    /**
165
     * @param array $keys
166
     * @param int $option
167
     * @param int $depth
168
     * @return mixed
169
     */
170
    public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
171
    {
172
        $callback = $this->getGenericCallback();
173
        return $callback(__FUNCTION__, func_get_args());
174
    }
175
176
    /**
177
     * @param \Psr\Cache\CacheItemInterface $item
178
     * @return mixed
179
     */
180
    public function setItem(CacheItemInterface $item)
181
    {
182
        $callback = $this->getGenericCallback();
183
        return $callback(__FUNCTION__, func_get_args());
184
    }
185
186
    /**
187
     * @return mixed
188
     */
189
    public function clean()
190
    {
191
        $callback = $this->getGenericCallback();
192
        return $callback(__FUNCTION__, func_get_args());
193
    }
194
195
    /**
196
     * @return mixed
197
     */
198
    public function getStats()
199
    {
200
        $callback = $this->getGenericCallback();
201
        return $callback(__FUNCTION__, func_get_args());
202
    }
203
204
    /**
205
     * @param string $tagName
206
     * @return mixed
207
     */
208
    public function getItemsByTag($tagName)
209
    {
210
        $callback = $this->getGenericCallback();
211
        return $callback(__FUNCTION__, func_get_args());
212
    }
213
214
    /**
215
     * @param array $tagNames
216
     * @return mixed
217
     */
218
    public function getItemsByTags(array $tagNames)
219
    {
220
        $callback = $this->getGenericCallback();
221
        return $callback(__FUNCTION__, func_get_args());
222
    }
223
224
    /**
225
     * @param array $tagNames
226
     * @param int $option
227
     * @param int $depth
228
     * @return mixed
229
     */
230
    public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
231
    {
232
        $callback = $this->getGenericCallback();
233
        return $callback(__FUNCTION__, func_get_args());
234
    }
235
236
    /**
237
     * @param string $tagName
238
     * @return mixed
239
     */
240
    public function deleteItemsByTag($tagName)
241
    {
242
        $callback = $this->getGenericCallback();
243
        return $callback(__FUNCTION__, func_get_args());
244
    }
245
246
    /**
247
     * @param array $tagNames
248
     * @return mixed
249
     */
250
    public function deleteItemsByTags(array $tagNames)
251
    {
252
        $callback = $this->getGenericCallback();
253
        return $callback(__FUNCTION__, func_get_args());
254
    }
255
256
    /**
257
     * @param string $tagName
258
     * @param int $step
259
     * @return mixed
260
     */
261
    public function incrementItemsByTag($tagName, $step = 1)
262
    {
263
        $callback = $this->getGenericCallback();
264
        return $callback(__FUNCTION__, func_get_args());
265
    }
266
267
    /**
268
     * @param array $tagNames
269
     * @param int $step
270
     * @return mixed
271
     */
272
    public function incrementItemsByTags(array $tagNames, $step = 1)
273
    {
274
        $callback = $this->getGenericCallback();
275
        return $callback(__FUNCTION__, func_get_args());
276
    }
277
278
    /**
279
     * @param string $tagName
280
     * @param int $step
281
     * @return mixed
282
     */
283
    public function decrementItemsByTag($tagName, $step = 1)
284
    {
285
        $callback = $this->getGenericCallback();
286
        return $callback(__FUNCTION__, func_get_args());
287
    }
288
289
    /**
290
     * @param array $tagNames
291
     * @param int $step
292
     * @return mixed
293
     */
294
    public function decrementItemsByTags(array $tagNames, $step = 1)
295
    {
296
        $callback = $this->getGenericCallback();
297
        return $callback(__FUNCTION__, func_get_args());
298
    }
299
300
    /**
301
     * @param string $tagName
302
     * @param array|string $data
303
     * @return mixed
304
     */
305
    public function appendItemsByTag($tagName, $data)
306
    {
307
        $callback = $this->getGenericCallback();
308
        return $callback(__FUNCTION__, func_get_args());
309
    }
310
311
    /**
312
     * @param array $tagNames
313
     * @param array|string $data
314
     * @return mixed
315
     */
316
    public function appendItemsByTags(array $tagNames, $data)
317
    {
318
        $callback = $this->getGenericCallback();
319
        return $callback(__FUNCTION__, func_get_args());
320
    }
321
322
    /**
323
     * @param string $tagName
324
     * @param array|string $data
325
     * @return mixed
326
     */
327
    public function prependItemsByTag($tagName, $data)
328
    {
329
        $callback = $this->getGenericCallback();
330
        return $callback(__FUNCTION__, func_get_args());
331
    }
332
333
    /**
334
     * @param array $tagNames
335
     * @param array|string $data
336
     * @return mixed
337
     */
338
    public function prependItemsByTags(array $tagNames, $data)
339
    {
340
        $callback = $this->getGenericCallback();
341
        return $callback(__FUNCTION__, func_get_args());
342
    }
343
344
    /**
345
     * @param \Psr\Cache\CacheItemInterface $item
346
     * @return mixed
347
     */
348
    public function detachItem(CacheItemInterface $item)
349
    {
350
        $callback = $this->getGenericCallback();
351
        return $callback(__FUNCTION__, func_get_args());
352
    }
353
354
    /**
355
     * @return mixed
356
     */
357
    public function detachAllItems()
358
    {
359
        $callback = $this->getGenericCallback();
360
        return $callback(__FUNCTION__, func_get_args());
361
    }
362
363
    /**
364
     * @param \Psr\Cache\CacheItemInterface $item
365
     * @return mixed
366
     */
367
    public function attachItem(CacheItemInterface $item)
368
    {
369
        $callback = $this->getGenericCallback();
370
        return $callback(__FUNCTION__, func_get_args());
371
    }
372
373
    /**
374
     * @param \Psr\Cache\CacheItemInterface $item
375
     * @return mixed
376
     */
377
    public function isAttached(CacheItemInterface $item)
378
    {
379
        $callback = $this->getGenericCallback();
380
        return $callback(__FUNCTION__, func_get_args());
381
    }
382
383
    /**
384
     * @param \phpFastCache\EventManager $em
385
     */
386
    public function setEventManager(EventManager $em)
387
    {
388
        $callback = $this->getGenericCallback();
389
        return $callback(__FUNCTION__, func_get_args());
390
    }
391
}