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
|
|
|
|
15
|
|
|
namespace phpFastCache\Drivers\Devnull; |
16
|
|
|
|
17
|
|
|
use phpFastCache\Core\DriverAbstract; |
18
|
|
|
use phpFastCache\Core\StandardPsr6StructureTrait; |
19
|
|
|
use phpFastCache\Entities\driverStatistic; |
20
|
|
|
use phpFastCache\Exceptions\phpFastCacheDriverCheckException; |
21
|
|
|
use phpFastCache\Exceptions\phpFastCacheDriverException; |
22
|
|
|
use Psr\Cache\CacheItemInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Driver |
26
|
|
|
* @package phpFastCache\Drivers |
27
|
|
|
*/ |
28
|
|
|
class Driver extends DriverAbstract |
29
|
|
|
{ |
30
|
|
|
use StandardPsr6StructureTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Driver constructor. |
34
|
|
|
* @param array $config |
35
|
|
|
* @throws phpFastCacheDriverException |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function __construct(array $config = []) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->setup($config); |
40
|
|
|
|
41
|
|
|
if (!$this->driverCheck()) { |
42
|
|
|
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
public function driverCheck() |
50
|
|
|
{ |
51
|
|
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
56
|
|
|
* @return mixed |
57
|
|
|
* @throws \InvalidArgumentException |
58
|
|
|
*/ |
59
|
|
|
protected function driverWrite(CacheItemInterface $item) |
60
|
|
|
{ |
61
|
|
|
/** |
62
|
|
|
* Check for Cross-Driver type confusion |
63
|
|
|
*/ |
64
|
|
|
if ($item instanceof Item) { |
65
|
|
|
return true; |
66
|
|
|
} else { |
67
|
|
|
throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
|
|
protected function driverRead(CacheItemInterface $item) |
76
|
|
|
{ |
77
|
|
|
return null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param \Psr\Cache\CacheItemInterface $item |
82
|
|
|
* @return bool |
83
|
|
|
* @throws \InvalidArgumentException |
84
|
|
|
*/ |
85
|
|
|
protected function driverDelete(CacheItemInterface $item) |
86
|
|
|
{ |
87
|
|
|
/** |
88
|
|
|
* Check for Cross-Driver type confusion |
89
|
|
|
*/ |
90
|
|
|
if ($item instanceof Item) { |
91
|
|
|
return true; |
92
|
|
|
} else { |
93
|
|
|
throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
protected function driverClear() |
101
|
|
|
{ |
102
|
|
|
return true; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
protected function driverConnect() |
109
|
|
|
{ |
110
|
|
|
return true; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/******************** |
114
|
|
|
* |
115
|
|
|
* PSR-6 Extended Methods |
116
|
|
|
* |
117
|
|
|
*******************/ |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return driverStatistic |
121
|
|
|
*/ |
122
|
|
|
public function getStats() |
123
|
|
|
{ |
124
|
|
|
$stat = new driverStatistic(); |
125
|
|
|
$stat->setInfo('[Devfalse] A void info string') |
126
|
|
|
->setSize(0) |
127
|
|
|
->setData(implode(', ', array_keys($this->itemInstances))) |
128
|
|
|
->setRawData(false); |
129
|
|
|
|
130
|
|
|
return $stat; |
131
|
|
|
} |
132
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.