1 | <?php |
||
23 | trait DriverBaseTrait |
||
24 | { |
||
25 | use ExtendedCacheItemPoolTrait; |
||
26 | |||
27 | /** |
||
28 | * @var array default options, this will be merge to Driver's Options |
||
29 | */ |
||
30 | protected $config = []; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $fallback = false; |
||
36 | |||
37 | /** |
||
38 | * @var mixed Instance of driver service |
||
39 | */ |
||
40 | protected $instance; |
||
41 | |||
42 | /** |
||
43 | * @param $keyword |
||
44 | * @return string |
||
45 | */ |
||
46 | protected function encodeFilename($keyword) |
||
47 | { |
||
48 | return md5($keyword); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param $config_name |
||
53 | * @param string $value |
||
54 | */ |
||
55 | public function setup($config_name, $value = '') |
||
56 | { |
||
57 | /** |
||
58 | * Config for class |
||
59 | */ |
||
60 | if (is_array($config_name)) { |
||
61 | $this->config = array_merge($this->config, $config_name); |
||
62 | } else { |
||
63 | $this->config[ $config_name ] = $value; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return array |
||
69 | */ |
||
70 | public function getConfig() |
||
71 | { |
||
72 | return $this->config; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param $file |
||
77 | * @return string |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | protected function readfile($file) |
||
101 | |||
102 | /** |
||
103 | * Encode data types such as object/array |
||
104 | * for driver that does not support |
||
105 | * non-scalar value |
||
106 | * @param $data |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function encode($data) |
||
113 | |||
114 | /** |
||
115 | * Decode data types such as object/array |
||
116 | * for driver that does not support |
||
117 | * non-scalar value |
||
118 | * @param $value |
||
119 | * @return mixed |
||
120 | */ |
||
121 | protected function decode($value) |
||
130 | |||
131 | /** |
||
132 | * Check phpModules or CGI |
||
133 | * @return bool |
||
134 | */ |
||
135 | protected function isPHPModule() |
||
147 | |||
148 | |||
149 | /** |
||
150 | * @param $class |
||
151 | * @return bool |
||
152 | */ |
||
153 | protected function isExistingDriver($class) |
||
157 | |||
158 | |||
159 | /** |
||
160 | * @param $tag |
||
161 | * @return string |
||
162 | */ |
||
163 | protected function _getTagName($tag) |
||
167 | |||
168 | /** |
||
169 | * @param \phpFastCache\Cache\ExtendedCacheItemInterface $item |
||
170 | * @return array |
||
171 | */ |
||
172 | public function driverPreWrap(ExtendedCacheItemInterface $item) |
||
180 | |||
181 | /** |
||
182 | * @param array $wrapper |
||
183 | * @return mixed |
||
184 | */ |
||
185 | public function driverUnwrapData(array $wrapper) |
||
189 | |||
190 | /** |
||
191 | * @param array $wrapper |
||
192 | * @return mixed |
||
193 | */ |
||
194 | public function driverUnwrapTags(array $wrapper) |
||
198 | |||
199 | |||
200 | /** |
||
201 | * @param array $wrapper |
||
202 | * @return \DateTime |
||
203 | */ |
||
204 | public function driverUnwrapTime(array $wrapper) |
||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | public function getDriverName() |
||
218 | |||
219 | /** |
||
220 | * @param \phpFastCache\Cache\ExtendedCacheItemInterface $item |
||
221 | * @return bool |
||
222 | */ |
||
223 | public function driverWriteTags(ExtendedCacheItemInterface $item) |
||
280 | |||
281 | /** |
||
282 | * @param $key |
||
283 | * @return string |
||
284 | */ |
||
285 | public function getTagKey($key) |
||
289 | |||
290 | /** |
||
291 | * @param $key |
||
292 | * @return string |
||
293 | */ |
||
294 | public function getTagKeys(array $keys) |
||
302 | |||
303 | /** |
||
304 | * @param string $optionName |
||
305 | * @param mixed $optionValue |
||
306 | * @return bool |
||
307 | * @throws \InvalidArgumentException |
||
308 | */ |
||
309 | public static function isValidOption($optionName, $optionValue) |
||
317 | |||
318 | /** |
||
319 | * @return array |
||
320 | */ |
||
321 | public static function getRequiredOptions() |
||
325 | |||
326 | /** |
||
327 | * @return array |
||
328 | */ |
||
329 | public static function getValidOptions() |
||
333 | |||
334 | /** |
||
335 | * Serialization protection for frameworks |
||
336 | * with profiler such as Symfony, etc. |
||
337 | */ |
||
338 | public function __sleep() |
||
343 | |||
344 | /** |
||
345 | * Serialization protection for frameworks |
||
346 | * with profiler such as Symfony, etc. |
||
347 | */ |
||
348 | public function __wakeup() |
||
356 | } |
$file
can contain request data and is used in file inclusion context(s) leading to a potential security vulnerability.General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
For numeric data, we recommend to explicitly cast the data: