Completed
Push — V6 ( e26840...2dc313 )
by Georges
02:16
created

ActOnAll::getConfigOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * This file is part of phpFastCache.
5
 *
6
 * @license MIT License (MIT)
7
 *
8
 * For full copyright and license information, please see the docs/CREDITS.txt file.
9
 *
10
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 *
13
 */
14
namespace phpFastCache\Helper;
15
16
use phpFastCache\CacheManager;
17
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
18
use phpFastCache\EventManager;
19
use Psr\Cache\CacheItemInterface;
20
21
/**
22
 * Class ActOnAll
23
 * @package phpFastCache\Helper
24
 */
25
class ActOnAll implements ExtendedCacheItemPoolInterface
26
{
27
28
    /**
29
     * @var ExtendedCacheItemPoolInterface[]
30
     */
31
    protected $instances = [];
32
33
    /**
34
     * ActOnAll constructor.
35
     */
36
    public function __construct()
37
    {
38
        $this->instances =& CacheManager::getInternalInstances();
39
    }
40
41
    /**
42
     * @return \Closure
43
     */
44
    protected function getGenericCallback()
45
    {
46
        return function($method, $args){
47
            $getterMethod = (strpos($method, 'get') === 0);
48
            $return = false;
49
50
            if($getterMethod){
51
                $return = [];
52
            }
53
54
            foreach ($this->instances as $instance)
55
            {
56
                $reflectionMethod = new \ReflectionMethod(get_class($instance), $method);
57
                if($getterMethod){
58
                    $return[ $instance->getDriverName() ] = $reflectionMethod->invokeArgs($instance, $args);
59
                }else{
60
                    $result = $reflectionMethod->invokeArgs($instance, $args);
61
                    if($result !== false){
62
                        $return = $result;
63
                    }
64
                }
65
            }
66
            return $return;
67
        };
68
    }
69
70
71
    /**
72
     * @param string $key
73
     * @return mixed
74
     */
75
    public function hasItem($key)
76
    {
77
        $callback = $this->getGenericCallback();
78
        return $callback(__FUNCTION__, func_get_args());
79
    }
80
81
    /**
82
     * @return mixed
83
     */
84
    public function clear()
85
    {
86
        $callback = $this->getGenericCallback();
87
        return $callback(__FUNCTION__, func_get_args());
88
    }
89
90
    /**
91
     * @param string $key
92
     * @return mixed
93
     */
94
    public function deleteItem($key)
95
    {
96
        $callback = $this->getGenericCallback();
97
        return $callback(__FUNCTION__, func_get_args());
98
    }
99
100
    /**
101
     * @param array $keys
102
     * @return mixed
103
     */
104
    public function deleteItems(array $keys)
105
    {
106
        $callback = $this->getGenericCallback();
107
        return $callback(__FUNCTION__, func_get_args());
108
    }
109
110
    /**
111
     * @param \Psr\Cache\CacheItemInterface $item
112
     * @return mixed
113
     */
114
    public function save(CacheItemInterface $item)
115
    {
116
        $callback = $this->getGenericCallback();
117
        return $callback(__FUNCTION__, func_get_args());
118
    }
119
120
    /**
121
     * @param \Psr\Cache\CacheItemInterface $item
122
     * @return mixed
123
     */
124
    public function saveDeferred(CacheItemInterface $item)
125
    {
126
        $callback = $this->getGenericCallback();
127
        return $callback(__FUNCTION__, func_get_args());
128
    }
129
130
    /**
131
     * @param array ...$items
132
     * @return mixed
133
     */
134
    public function saveMultiple(...$items)
135
    {
136
        $callback = $this->getGenericCallback();
137
        return $callback(__FUNCTION__, func_get_args());
138
    }
139
140
    /**
141
     * @return mixed
142
     */
143
    public function commit()
144
    {
145
        $callback = $this->getGenericCallback();
146
        return $callback(__FUNCTION__, func_get_args());
147
    }
148
149
    /**
150
     * @return mixed
151
     */
152
    public function getConfig()
153
    {
154
        $callback = $this->getGenericCallback();
155
        return $callback(__FUNCTION__, func_get_args());
156
    }
157
158
    /**
159
     * @return mixed
160
     */
161
    public function getConfigOption($optionName)
162
    {
163
        $callback = $this->getGenericCallback();
164
        return $callback(__FUNCTION__, func_get_args());
165
    }
166
167
    /**
168
     * @return mixed
169
     */
170
    public function getDriverName()
171
    {
172
        $callback = $this->getGenericCallback();
173
        return $callback(__FUNCTION__, func_get_args());
174
    }
175
176
    /**
177
     * @param string $key
178
     * @return mixed
179
     */
180
    public function getItem($key)
181
    {
182
        $callback = $this->getGenericCallback();
183
        return $callback(__FUNCTION__, func_get_args());
184
    }
185
186
    /**
187
     * @param array $keys
188
     * @return mixed
189
     */
190
    public function getItems(array $keys = [])
191
    {
192
        $callback = $this->getGenericCallback();
193
        return $callback(__FUNCTION__, func_get_args());
194
    }
195
196
    /**
197
     * @param array $keys
198
     * @param int $option
199
     * @param int $depth
200
     * @return mixed
201
     */
202
    public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
203
    {
204
        $callback = $this->getGenericCallback();
205
        return $callback(__FUNCTION__, func_get_args());
206
    }
207
208
    /**
209
     * @param \Psr\Cache\CacheItemInterface $item
210
     * @return mixed
211
     */
212
    public function setItem(CacheItemInterface $item)
213
    {
214
        $callback = $this->getGenericCallback();
215
        return $callback(__FUNCTION__, func_get_args());
216
    }
217
218
    /**
219
     * @return mixed
220
     */
221
    public function getHelp()
222
    {
223
        $callback = $this->getGenericCallback();
224
        return $callback(__FUNCTION__, func_get_args());
225
    }
226
227
    /**
228
     * @return mixed
229
     */
230
    public function getStats()
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 getItemsByTag($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 getItemsByTags(array $tagNames)
251
    {
252
        $callback = $this->getGenericCallback();
253
        return $callback(__FUNCTION__, func_get_args());
254
    }
255
256
    /**
257
     * @param array $tagNames
258
     * @param int $option
259
     * @param int $depth
260
     * @return mixed
261
     */
262
    public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
263
    {
264
        $callback = $this->getGenericCallback();
265
        return $callback(__FUNCTION__, func_get_args());
266
    }
267
268
    /**
269
     * @param string $tagName
270
     * @return mixed
271
     */
272
    public function deleteItemsByTag($tagName)
273
    {
274
        $callback = $this->getGenericCallback();
275
        return $callback(__FUNCTION__, func_get_args());
276
    }
277
278
    /**
279
     * @param array $tagNames
280
     * @return mixed
281
     */
282
    public function deleteItemsByTags(array $tagNames)
283
    {
284
        $callback = $this->getGenericCallback();
285
        return $callback(__FUNCTION__, func_get_args());
286
    }
287
288
    /**
289
     * @param string $tagName
290
     * @param int $step
291
     * @return mixed
292
     */
293
    public function incrementItemsByTag($tagName, $step = 1)
294
    {
295
        $callback = $this->getGenericCallback();
296
        return $callback(__FUNCTION__, func_get_args());
297
    }
298
299
    /**
300
     * @param array $tagNames
301
     * @param int $step
302
     * @return mixed
303
     */
304
    public function incrementItemsByTags(array $tagNames, $step = 1)
305
    {
306
        $callback = $this->getGenericCallback();
307
        return $callback(__FUNCTION__, func_get_args());
308
    }
309
310
    /**
311
     * @param string $tagName
312
     * @param int $step
313
     * @return mixed
314
     */
315
    public function decrementItemsByTag($tagName, $step = 1)
316
    {
317
        $callback = $this->getGenericCallback();
318
        return $callback(__FUNCTION__, func_get_args());
319
    }
320
321
    /**
322
     * @param array $tagNames
323
     * @param int $step
324
     * @return mixed
325
     */
326
    public function decrementItemsByTags(array $tagNames, $step = 1)
327
    {
328
        $callback = $this->getGenericCallback();
329
        return $callback(__FUNCTION__, func_get_args());
330
    }
331
332
    /**
333
     * @param string $tagName
334
     * @param array|string $data
335
     * @return mixed
336
     */
337
    public function appendItemsByTag($tagName, $data)
338
    {
339
        $callback = $this->getGenericCallback();
340
        return $callback(__FUNCTION__, func_get_args());
341
    }
342
343
    /**
344
     * @param array $tagNames
345
     * @param array|string $data
346
     * @return mixed
347
     */
348
    public function appendItemsByTags(array $tagNames, $data)
349
    {
350
        $callback = $this->getGenericCallback();
351
        return $callback(__FUNCTION__, func_get_args());
352
    }
353
354
    /**
355
     * @param string $tagName
356
     * @param array|string $data
357
     * @return mixed
358
     */
359
    public function prependItemsByTag($tagName, $data)
360
    {
361
        $callback = $this->getGenericCallback();
362
        return $callback(__FUNCTION__, func_get_args());
363
    }
364
365
    /**
366
     * @param array $tagNames
367
     * @param array|string $data
368
     * @return mixed
369
     */
370
    public function prependItemsByTags(array $tagNames, $data)
371
    {
372
        $callback = $this->getGenericCallback();
373
        return $callback(__FUNCTION__, func_get_args());
374
    }
375
376
    /**
377
     * @param array $tagNames
378
     * @return mixed
379
     */
380
    public function getItemsByTagsAll(array $tagNames)
381
    {
382
        $callback = $this->getGenericCallback();
383
        return $callback(__FUNCTION__, func_get_args());
384
    }
385
386
    /**
387
     * @param array $tagNames
388
     * @return mixed
389
     */
390
    public function deleteItemsByTagsAll(array $tagNames)
391
    {
392
        $callback = $this->getGenericCallback();
393
        return $callback(__FUNCTION__, func_get_args());
394
    }
395
396
    /**
397
     * @param array $tagNames
398
     * @param int $step
399
     * @return mixed
400
     */
401
    public function incrementItemsByTagsAll(array $tagNames, $step = 1)
402
    {
403
        $callback = $this->getGenericCallback();
404
        return $callback(__FUNCTION__, func_get_args());
405
    }
406
407
    /**
408
     * @param array $tagNames
409
     * @param int $step
410
     * @return mixed
411
     */
412
    public function decrementItemsByTagsAll(array $tagNames, $step = 1)
413
    {
414
        $callback = $this->getGenericCallback();
415
        return $callback(__FUNCTION__, func_get_args());
416
    }
417
418
    /**
419
     * @param array $tagNames
420
     * @param array|string $data
421
     * @return mixed
422
     */
423
    public function appendItemsByTagsAll(array $tagNames, $data)
424
    {
425
        $callback = $this->getGenericCallback();
426
        return $callback(__FUNCTION__, func_get_args());
427
    }
428
429
    /**
430
     * @param array $tagNames
431
     * @param array|string $data
432
     * @return mixed
433
     */
434
    public function prependItemsByTagsAll(array $tagNames, $data)
435
    {
436
        $callback = $this->getGenericCallback();
437
        return $callback(__FUNCTION__, func_get_args());
438
    }
439
440
    /**
441
     * @param \Psr\Cache\CacheItemInterface $item
442
     * @return mixed
443
     */
444
    public function detachItem(CacheItemInterface $item)
445
    {
446
        $callback = $this->getGenericCallback();
447
        return $callback(__FUNCTION__, func_get_args());
448
    }
449
450
    /**
451
     * @return mixed
452
     */
453
    public function detachAllItems()
454
    {
455
        $callback = $this->getGenericCallback();
456
        return $callback(__FUNCTION__, func_get_args());
457
    }
458
459
    /**
460
     * @param \Psr\Cache\CacheItemInterface $item
461
     * @return mixed
462
     */
463
    public function attachItem(CacheItemInterface $item)
464
    {
465
        $callback = $this->getGenericCallback();
466
        return $callback(__FUNCTION__, func_get_args());
467
    }
468
469
    /**
470
     * @param \Psr\Cache\CacheItemInterface $item
471
     * @return mixed
472
     */
473
    public function isAttached(CacheItemInterface $item)
474
    {
475
        $callback = $this->getGenericCallback();
476
        return $callback(__FUNCTION__, func_get_args());
477
    }
478
479
    /**
480
     * @param \phpFastCache\EventManager $em
481
     */
482
    public function setEventManager(EventManager $em)
483
    {
484
        $callback = $this->getGenericCallback();
485
        return $callback(__FUNCTION__, func_get_args());
486
    }
487
}