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\Entities; |
15
|
|
|
|
16
|
|
|
use ArrayAccess; |
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
use LogicException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class driverStatistic |
22
|
|
|
* @package phpFastCache\Entities |
23
|
|
|
*/ |
24
|
|
|
class driverStatistic implements ArrayAccess |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $info = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $size = ''; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $data = ''; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var mixed |
43
|
|
|
*/ |
44
|
|
|
protected $rawData; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string|bool Return infos or false if no information available |
48
|
|
|
*/ |
49
|
|
|
public function getInfo() |
50
|
|
|
{ |
51
|
|
|
return $this->info; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return int|bool Return size in octet or false if no information available |
56
|
|
|
*/ |
57
|
|
|
public function getSize() |
58
|
|
|
{ |
59
|
|
|
return $this->size; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public function getData() |
66
|
|
|
{ |
67
|
|
|
return $this->data; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $info |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function setInfo($info) |
75
|
|
|
{ |
76
|
|
|
$this->info = ($info ?: false); |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param int $size |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setSize($size) |
87
|
|
|
{ |
88
|
|
|
$this->size = ($size ?: false); |
|
|
|
|
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param mixed $data |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
|
|
public function setData($data) |
98
|
|
|
{ |
99
|
|
|
$this->data = ($data ?: false); |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getRawData() |
108
|
|
|
{ |
109
|
|
|
return $this->rawData; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param mixed $raw |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
|
|
public function setRawData($raw) |
117
|
|
|
{ |
118
|
|
|
$this->rawData = $raw; |
119
|
|
|
|
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
public function getPublicDesc() |
127
|
|
|
{ |
128
|
|
|
return[ |
129
|
|
|
'Info' => 'Cache Information', |
130
|
|
|
'Size' => 'Cache Size', |
131
|
|
|
'Data' => 'Cache items keys', |
132
|
|
|
'RawData' => 'Cache raw data', |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/***************** |
137
|
|
|
* ArrayAccess |
138
|
|
|
*****************/ |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $offset |
142
|
|
|
* @param string $value |
143
|
|
|
* @throws InvalidArgumentException |
144
|
|
|
* @throws LogicException |
145
|
|
|
*/ |
146
|
|
View Code Duplication |
public function offsetSet($offset, $value) |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); |
149
|
|
|
if (!is_string($offset)) { |
150
|
|
|
throw new InvalidArgumentException('$offset must be a string'); |
151
|
|
|
} else { |
152
|
|
|
if (property_exists($this, $offset)) { |
153
|
|
|
$this->{$offset} = $value; |
154
|
|
|
} else { |
155
|
|
|
throw new LogicException("Property {$offset} does not exists"); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $offset |
162
|
|
|
* @return bool |
163
|
|
|
* @throws InvalidArgumentException |
164
|
|
|
* @throws LogicException |
165
|
|
|
*/ |
166
|
|
View Code Duplication |
public function offsetExists($offset) |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); |
169
|
|
|
if (!is_string($offset)) { |
170
|
|
|
throw new InvalidArgumentException('$offset must be a string'); |
171
|
|
|
} else { |
172
|
|
|
if (property_exists($this, $offset)) { |
173
|
|
|
return isset($this->{$offset}); |
174
|
|
|
} else { |
175
|
|
|
throw new LogicException("Property {$offset} does not exists"); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $offset |
182
|
|
|
* @throws InvalidArgumentException |
183
|
|
|
* @throws LogicException |
184
|
|
|
*/ |
185
|
|
View Code Duplication |
public function offsetUnset($offset) |
|
|
|
|
186
|
|
|
{ |
187
|
|
|
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); |
188
|
|
|
if (!is_string($offset)) { |
189
|
|
|
throw new InvalidArgumentException('$offset must be a string'); |
190
|
|
|
} else { |
191
|
|
|
if (property_exists($this, $offset)) { |
192
|
|
|
unset($this->{$offset}); |
193
|
|
|
} else { |
194
|
|
|
throw new LogicException("Property {$offset} does not exists"); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $offset |
201
|
|
|
* @return string |
202
|
|
|
* @throws InvalidArgumentException |
203
|
|
|
* @throws LogicException |
204
|
|
|
*/ |
205
|
|
View Code Duplication |
public function offsetGet($offset) |
|
|
|
|
206
|
|
|
{ |
207
|
|
|
trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); |
208
|
|
|
if (!is_string($offset)) { |
209
|
|
|
throw new InvalidArgumentException('$offset must be a string'); |
210
|
|
|
} else { |
211
|
|
|
if (property_exists($this, $offset)) { |
212
|
|
|
return isset($this->{$offset}) ? $this->{$offset} : null; |
213
|
|
|
} else { |
214
|
|
|
throw new LogicException("Property {$offset} does not exists"); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
private function getDeprecatedMsg() |
223
|
|
|
{ |
224
|
|
|
return 'You should consider upgrading your code and treat the statistic array as an object. |
225
|
|
|
The arrayAccess compatibility will be removed in the next major release'; |
226
|
|
|
} |
227
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..