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 getDriverName() |
162
|
|
|
{ |
163
|
|
|
$callback = $this->getGenericCallback(); |
164
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string $key |
169
|
|
|
* @return mixed |
170
|
|
|
*/ |
171
|
|
|
public function getItem($key) |
172
|
|
|
{ |
173
|
|
|
$callback = $this->getGenericCallback(); |
174
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param array $keys |
179
|
|
|
* @return mixed |
180
|
|
|
*/ |
181
|
|
|
public function getItems(array $keys = []) |
182
|
|
|
{ |
183
|
|
|
$callback = $this->getGenericCallback(); |
184
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param array $keys |
189
|
|
|
* @param int $option |
190
|
|
|
* @param int $depth |
191
|
|
|
* @return mixed |
192
|
|
|
*/ |
193
|
|
|
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
194
|
|
|
{ |
195
|
|
|
$callback = $this->getGenericCallback(); |
196
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
201
|
|
|
* @return mixed |
202
|
|
|
*/ |
203
|
|
|
public function setItem(CacheItemInterface $item) |
204
|
|
|
{ |
205
|
|
|
$callback = $this->getGenericCallback(); |
206
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return mixed |
211
|
|
|
*/ |
212
|
|
|
public function getHelp() |
213
|
|
|
{ |
214
|
|
|
$callback = $this->getGenericCallback(); |
215
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return mixed |
220
|
|
|
*/ |
221
|
|
|
public function getStats() |
222
|
|
|
{ |
223
|
|
|
$callback = $this->getGenericCallback(); |
224
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param string $tagName |
229
|
|
|
* @return mixed |
230
|
|
|
*/ |
231
|
|
|
public function getItemsByTag($tagName) |
232
|
|
|
{ |
233
|
|
|
$callback = $this->getGenericCallback(); |
234
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param array $tagNames |
239
|
|
|
* @return mixed |
240
|
|
|
*/ |
241
|
|
|
public function getItemsByTags(array $tagNames) |
242
|
|
|
{ |
243
|
|
|
$callback = $this->getGenericCallback(); |
244
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param array $tagNames |
249
|
|
|
* @param int $option |
250
|
|
|
* @param int $depth |
251
|
|
|
* @return mixed |
252
|
|
|
*/ |
253
|
|
|
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
254
|
|
|
{ |
255
|
|
|
$callback = $this->getGenericCallback(); |
256
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param string $tagName |
261
|
|
|
* @return mixed |
262
|
|
|
*/ |
263
|
|
|
public function deleteItemsByTag($tagName) |
264
|
|
|
{ |
265
|
|
|
$callback = $this->getGenericCallback(); |
266
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param array $tagNames |
271
|
|
|
* @return mixed |
272
|
|
|
*/ |
273
|
|
|
public function deleteItemsByTags(array $tagNames) |
274
|
|
|
{ |
275
|
|
|
$callback = $this->getGenericCallback(); |
276
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @param string $tagName |
281
|
|
|
* @param int $step |
282
|
|
|
* @return mixed |
283
|
|
|
*/ |
284
|
|
|
public function incrementItemsByTag($tagName, $step = 1) |
285
|
|
|
{ |
286
|
|
|
$callback = $this->getGenericCallback(); |
287
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param array $tagNames |
292
|
|
|
* @param int $step |
293
|
|
|
* @return mixed |
294
|
|
|
*/ |
295
|
|
|
public function incrementItemsByTags(array $tagNames, $step = 1) |
296
|
|
|
{ |
297
|
|
|
$callback = $this->getGenericCallback(); |
298
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @param string $tagName |
303
|
|
|
* @param int $step |
304
|
|
|
* @return mixed |
305
|
|
|
*/ |
306
|
|
|
public function decrementItemsByTag($tagName, $step = 1) |
307
|
|
|
{ |
308
|
|
|
$callback = $this->getGenericCallback(); |
309
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param array $tagNames |
314
|
|
|
* @param int $step |
315
|
|
|
* @return mixed |
316
|
|
|
*/ |
317
|
|
|
public function decrementItemsByTags(array $tagNames, $step = 1) |
318
|
|
|
{ |
319
|
|
|
$callback = $this->getGenericCallback(); |
320
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param string $tagName |
325
|
|
|
* @param array|string $data |
326
|
|
|
* @return mixed |
327
|
|
|
*/ |
328
|
|
|
public function appendItemsByTag($tagName, $data) |
329
|
|
|
{ |
330
|
|
|
$callback = $this->getGenericCallback(); |
331
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @param array $tagNames |
336
|
|
|
* @param array|string $data |
337
|
|
|
* @return mixed |
338
|
|
|
*/ |
339
|
|
|
public function appendItemsByTags(array $tagNames, $data) |
340
|
|
|
{ |
341
|
|
|
$callback = $this->getGenericCallback(); |
342
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param string $tagName |
347
|
|
|
* @param array|string $data |
348
|
|
|
* @return mixed |
349
|
|
|
*/ |
350
|
|
|
public function prependItemsByTag($tagName, $data) |
351
|
|
|
{ |
352
|
|
|
$callback = $this->getGenericCallback(); |
353
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @param array $tagNames |
358
|
|
|
* @param array|string $data |
359
|
|
|
* @return mixed |
360
|
|
|
*/ |
361
|
|
|
public function prependItemsByTags(array $tagNames, $data) |
362
|
|
|
{ |
363
|
|
|
$callback = $this->getGenericCallback(); |
364
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param array $tagNames |
369
|
|
|
* @return mixed |
370
|
|
|
*/ |
371
|
|
|
public function getItemsByTagsAll(array $tagNames) |
372
|
|
|
{ |
373
|
|
|
$callback = $this->getGenericCallback(); |
374
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @param array $tagNames |
379
|
|
|
* @return mixed |
380
|
|
|
*/ |
381
|
|
|
public function deleteItemsByTagsAll(array $tagNames) |
382
|
|
|
{ |
383
|
|
|
$callback = $this->getGenericCallback(); |
384
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* @param array $tagNames |
389
|
|
|
* @param int $step |
390
|
|
|
* @return mixed |
391
|
|
|
*/ |
392
|
|
|
public function incrementItemsByTagsAll(array $tagNames, $step = 1) |
393
|
|
|
{ |
394
|
|
|
$callback = $this->getGenericCallback(); |
395
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @param array $tagNames |
400
|
|
|
* @param int $step |
401
|
|
|
* @return mixed |
402
|
|
|
*/ |
403
|
|
|
public function decrementItemsByTagsAll(array $tagNames, $step = 1) |
404
|
|
|
{ |
405
|
|
|
$callback = $this->getGenericCallback(); |
406
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @param array $tagNames |
411
|
|
|
* @param array|string $data |
412
|
|
|
* @return mixed |
413
|
|
|
*/ |
414
|
|
|
public function appendItemsByTagsAll(array $tagNames, $data) |
415
|
|
|
{ |
416
|
|
|
$callback = $this->getGenericCallback(); |
417
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* @param array $tagNames |
422
|
|
|
* @param array|string $data |
423
|
|
|
* @return mixed |
424
|
|
|
*/ |
425
|
|
|
public function prependItemsByTagsAll(array $tagNames, $data) |
426
|
|
|
{ |
427
|
|
|
$callback = $this->getGenericCallback(); |
428
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
433
|
|
|
* @return mixed |
434
|
|
|
*/ |
435
|
|
|
public function detachItem(CacheItemInterface $item) |
436
|
|
|
{ |
437
|
|
|
$callback = $this->getGenericCallback(); |
438
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* @return mixed |
443
|
|
|
*/ |
444
|
|
|
public function detachAllItems() |
445
|
|
|
{ |
446
|
|
|
$callback = $this->getGenericCallback(); |
447
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
452
|
|
|
* @return mixed |
453
|
|
|
*/ |
454
|
|
|
public function attachItem(CacheItemInterface $item) |
455
|
|
|
{ |
456
|
|
|
$callback = $this->getGenericCallback(); |
457
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
462
|
|
|
* @return mixed |
463
|
|
|
*/ |
464
|
|
|
public function isAttached(CacheItemInterface $item) |
465
|
|
|
{ |
466
|
|
|
$callback = $this->getGenericCallback(); |
467
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @param \phpFastCache\EventManager $em |
472
|
|
|
*/ |
473
|
|
|
public function setEventManager(EventManager $em) |
474
|
|
|
{ |
475
|
|
|
$callback = $this->getGenericCallback(); |
476
|
|
|
return $callback(__FUNCTION__, func_get_args()); |
477
|
|
|
} |
478
|
|
|
} |