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