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) |
||
122 | { |
||
123 | return @unserialize($value); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Check phpModules or CGI |
||
128 | * @return bool |
||
129 | */ |
||
130 | protected function isPHPModule() |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @param $class |
||
146 | * @return bool |
||
147 | */ |
||
148 | protected function isExistingDriver($class) |
||
152 | |||
153 | |||
154 | /** |
||
155 | * @param $tag |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function _getTagName($tag) |
||
162 | |||
163 | /** |
||
164 | * @param \phpFastCache\Cache\ExtendedCacheItemInterface $item |
||
165 | * @return array |
||
166 | */ |
||
167 | public function driverPreWrap(ExtendedCacheItemInterface $item) |
||
175 | |||
176 | /** |
||
177 | * @param array $wrapper |
||
178 | * @return mixed |
||
179 | */ |
||
180 | public function driverUnwrapData(array $wrapper) |
||
184 | |||
185 | /** |
||
186 | * @param array $wrapper |
||
187 | * @return mixed |
||
188 | */ |
||
189 | public function driverUnwrapTags(array $wrapper) |
||
193 | |||
194 | |||
195 | /** |
||
196 | * @param array $wrapper |
||
197 | * @return \DateTime |
||
198 | */ |
||
199 | public function driverUnwrapTime(array $wrapper) |
||
203 | |||
204 | /** |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getDriverName() |
||
213 | |||
214 | /** |
||
215 | * @param \phpFastCache\Cache\ExtendedCacheItemInterface $item |
||
216 | * @return bool |
||
217 | */ |
||
218 | public function driverWriteTags(ExtendedCacheItemInterface $item) |
||
275 | |||
276 | /** |
||
277 | * @param $key |
||
278 | * @return string |
||
279 | */ |
||
280 | public function getTagKey($key) |
||
284 | |||
285 | /** |
||
286 | * @param $key |
||
287 | * @return string |
||
288 | */ |
||
289 | public function getTagKeys(array $keys) |
||
297 | |||
298 | /** |
||
299 | * @param string $optionName |
||
300 | * @param mixed $optionValue |
||
301 | * @return bool |
||
302 | * @throws \InvalidArgumentException |
||
303 | */ |
||
304 | public static function isValidOption($optionName, $optionValue) |
||
312 | |||
313 | /** |
||
314 | * @return array |
||
315 | */ |
||
316 | public static function getRequiredOptions() |
||
320 | |||
321 | /** |
||
322 | * @return array |
||
323 | */ |
||
324 | public static function getValidOptions() |
||
328 | } |
$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: