1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of Phpfastcache. |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. |
10
|
|
|
* |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors |
13
|
|
|
*/ |
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Phpfastcache\Core\Pool; |
17
|
|
|
|
18
|
|
|
use Phpfastcache\Core\Item\ExtendedCacheItemInterface; |
19
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; |
20
|
|
|
|
21
|
|
|
trait DriverPoolAbstractTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @return bool |
25
|
|
|
*/ |
26
|
|
|
abstract protected function driverCheck(): bool; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
abstract protected function driverConnect(): bool; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param ExtendedCacheItemInterface $item |
35
|
|
|
* @return ?array |
36
|
|
|
*/ |
37
|
|
|
abstract protected function driverRead(ExtendedCacheItemInterface $item): ?array; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param ExtendedCacheItemInterface $item |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
abstract protected function driverWrite(ExtendedCacheItemInterface $item): bool; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ExtendedCacheItemInterface $item |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
abstract protected function driverDelete(ExtendedCacheItemInterface $item): bool; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
|
|
abstract protected function driverClear(): bool; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param ExtendedCacheItemInterface $item |
58
|
|
|
* @param string $expectedClassType |
59
|
|
|
* @throws PhpfastcacheInvalidArgumentException |
60
|
|
|
*/ |
61
|
|
|
protected function assertCacheItemType(ExtendedCacheItemInterface $item, string $expectedClassType): void |
62
|
|
|
{ |
63
|
|
|
if (!($item instanceof $expectedClassType)) { |
64
|
|
|
throw new PhpfastcacheInvalidArgumentException( |
65
|
|
|
\sprintf('Cross-driver type confusion detected: Expected "%s" object, got "%s"', $expectedClassType, $item::class) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|