This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Part of the Joomla Framework Cache Package |
||
4 | * |
||
5 | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
||
6 | * @license GNU General Public License version 2 or later; see LICENSE |
||
7 | */ |
||
8 | |||
9 | namespace Joomla\Cache; |
||
10 | |||
11 | use Joomla\Cache\Exception\InvalidArgumentException; |
||
12 | use Joomla\Cache\Item\HasExpirationDateInterface; |
||
13 | use Psr\Cache\CacheItemInterface; |
||
14 | use Psr\SimpleCache\CacheInterface; |
||
15 | |||
16 | /** |
||
17 | * Joomla! Caching Class |
||
18 | * |
||
19 | * @since 1.0 |
||
20 | * @deprecated The joomla/cache package is deprecated |
||
21 | */ |
||
22 | abstract class AbstractCacheItemPool implements CacheItemPoolInterface, CacheInterface |
||
0 ignored issues
–
show
|
|||
23 | { |
||
24 | /** |
||
25 | * The options for the cache object. |
||
26 | * |
||
27 | * @var array|\ArrayAccess |
||
28 | * @since 1.0 |
||
29 | */ |
||
30 | protected $options; |
||
31 | |||
32 | /** |
||
33 | * The deferred items to store |
||
34 | * |
||
35 | * @var Item\Item[] |
||
36 | * @since 1.0 |
||
37 | */ |
||
38 | private $deferred = []; |
||
39 | |||
40 | /** |
||
41 | * Constructor. |
||
42 | * |
||
43 | * @param array|\ArrayAccess $options An options array, or an object that implements \ArrayAccess |
||
44 | * |
||
45 | * @since 1.0 |
||
46 | * @throws InvalidArgumentException |
||
47 | */ |
||
48 | 94 | public function __construct($options = []) |
|
49 | { |
||
50 | 94 | if (!($options instanceof \ArrayAccess || is_array($options))) |
|
51 | { |
||
52 | throw new InvalidArgumentException(sprintf('%s requires an options array or an object that implements \\ArrayAccess', get_class($this))); |
||
0 ignored issues
–
show
The class
Joomla\Cache\Exception\InvalidArgumentException has been deprecated with message: The joomla/cache package is deprecated
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead. ![]() |
|||
53 | } |
||
54 | |||
55 | 94 | $this->options = $options; |
|
56 | 94 | } |
|
57 | |||
58 | /** |
||
59 | * Returns a traversable set of cache items. |
||
60 | * |
||
61 | * @param string[] $keys An indexed array of keys of items to retrieve. |
||
62 | * |
||
63 | * @return array A traversable collection of Cache Items keyed by the cache keys of each item. |
||
64 | * A Cache item will be returned for each key, even if that key is not found. |
||
65 | * |
||
66 | * @since __DEPLOY_VERSION__ |
||
67 | */ |
||
68 | 16 | public function getItems(array $keys = []) |
|
69 | { |
||
70 | 16 | $result = []; |
|
71 | |||
72 | 16 | foreach ($keys as $key) |
|
73 | { |
||
74 | 16 | $result[$key] = $this->getItem($key); |
|
75 | } |
||
76 | |||
77 | 16 | return $result; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Get an option from the Cache instance. |
||
82 | * |
||
83 | * @param string $key The name of the option to get. |
||
84 | * |
||
85 | * @return mixed The option value. |
||
86 | * |
||
87 | * @since 1.0 |
||
88 | */ |
||
89 | 10 | public function getOption($key) |
|
90 | { |
||
91 | 10 | return isset($this->options[$key]) ? $this->options[$key] : null; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Removes multiple items from the pool. |
||
96 | * |
||
97 | * @param array $keys An array of keys that should be removed from the pool. |
||
98 | * |
||
99 | * @return boolean True if the items were successfully removed. False if there was an error. |
||
100 | * |
||
101 | * @since __DEPLOY_VERSION__ |
||
102 | */ |
||
103 | 8 | public function deleteItems(array $keys) |
|
104 | { |
||
105 | 8 | foreach ($keys as $key) |
|
106 | { |
||
107 | 8 | if (!$this->deleteItem($key)) |
|
108 | { |
||
109 | 8 | return false; |
|
110 | } |
||
111 | } |
||
112 | |||
113 | 8 | return true; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * Set an option for the Cache instance. |
||
118 | * |
||
119 | * @param string $key The name of the option to set. |
||
120 | * @param mixed $value The option value to set. |
||
121 | * |
||
122 | * @return $this |
||
123 | * |
||
124 | * @since 1.0 |
||
125 | */ |
||
126 | 5 | public function setOption($key, $value) |
|
127 | { |
||
128 | 5 | $this->options[$key] = $value; |
|
129 | |||
130 | 5 | return $this; |
|
131 | } |
||
132 | |||
133 | /** |
||
134 | * Sets a cache item to be persisted later. |
||
135 | * |
||
136 | * @param CacheItemInterface $item The cache item to save. |
||
137 | * |
||
138 | * @return boolean False if the item could not be queued or if a commit was attempted and failed. True otherwise. |
||
139 | * |
||
140 | * @since __DEPLOY_VERSION__ |
||
141 | */ |
||
142 | 15 | public function saveDeferred(CacheItemInterface $item) |
|
143 | { |
||
144 | 15 | $this->deferred[$item->getKey()] = $item; |
|
145 | |||
146 | 15 | return true; |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * Persists any deferred cache items. |
||
151 | * |
||
152 | * @return boolean True if all not-yet-saved items were successfully saved or there were none. False otherwise. |
||
153 | * |
||
154 | * @since __DEPLOY_VERSION__ |
||
155 | */ |
||
156 | 15 | public function commit() |
|
157 | { |
||
158 | 15 | $result = true; |
|
159 | |||
160 | 15 | foreach ($this->deferred as $key => $deferred) |
|
161 | { |
||
162 | 15 | $saveResult = $this->save($deferred); |
|
163 | |||
164 | 15 | if (true === $saveResult) |
|
165 | { |
||
166 | 15 | unset($this->deferred[$key]); |
|
167 | } |
||
168 | |||
169 | 15 | $result = $result && $saveResult; |
|
170 | } |
||
171 | |||
172 | 15 | return $result; |
|
173 | } |
||
174 | |||
175 | /** |
||
176 | * Fetches a value from the cache. |
||
177 | * |
||
178 | * @param string $key The unique key of this item in the cache. |
||
179 | * @param mixed $default Default value to return if the key does not exist. |
||
180 | * |
||
181 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
||
182 | * |
||
183 | * @since __DEPLOY_VERSION__ |
||
184 | */ |
||
185 | 16 | public function get($key, $default = null) |
|
186 | { |
||
187 | 16 | $item = $this->getItem($key); |
|
188 | |||
189 | 16 | if (!$item->isHit()) |
|
190 | { |
||
191 | 8 | return $default; |
|
192 | } |
||
193 | |||
194 | 16 | return $item->get(); |
|
195 | } |
||
196 | |||
197 | /** |
||
198 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
199 | * |
||
200 | * @param string $key The key of the item to store. |
||
201 | * @param mixed $value The value of the item to store, must be serializable. |
||
202 | * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
203 | * the driver supports TTL then the library may set a default value |
||
204 | * for it or let the driver take care of that. |
||
205 | * |
||
206 | * @return boolean True on success and false on failure. |
||
207 | * |
||
208 | * @since __DEPLOY_VERSION__ |
||
209 | */ |
||
210 | 21 | public function set($key, $value, $ttl = null) |
|
211 | { |
||
212 | 21 | $item = $this->getItem($key); |
|
213 | 21 | $item->set($value); |
|
214 | 21 | $item->expiresAfter($ttl); |
|
215 | |||
216 | 21 | return $this->save($item); |
|
217 | } |
||
218 | |||
219 | /** |
||
220 | * Delete an item from the cache by its unique key. |
||
221 | * |
||
222 | * @param string $key The unique cache key of the item to delete. |
||
223 | * |
||
224 | * @return boolean True if the item was successfully removed. False if there was an error. |
||
225 | * |
||
226 | * @since __DEPLOY_VERSION__ |
||
227 | */ |
||
228 | 5 | public function delete($key) |
|
229 | { |
||
230 | 5 | return $this->deleteItem($key); |
|
231 | } |
||
232 | |||
233 | /** |
||
234 | * Obtains multiple cache items by their unique keys. |
||
235 | * |
||
236 | * @param iterable $keys A list of keys that can obtained in a single operation. |
||
237 | * @param mixed $default Default value to return for keys that do not exist. |
||
238 | * |
||
239 | * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
||
240 | * |
||
241 | * @since __DEPLOY_VERSION__ |
||
242 | * @throws InvalidArgumentException |
||
243 | */ |
||
244 | 5 | public function getMultiple($keys, $default = null) |
|
245 | { |
||
246 | 5 | View Code Duplication | if (!is_array($keys)) |
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
247 | { |
||
248 | if (!($keys instanceof \Traversable)) |
||
249 | { |
||
250 | throw new InvalidArgumentException('$keys is neither an array nor Traversable'); |
||
0 ignored issues
–
show
The class
Joomla\Cache\Exception\InvalidArgumentException has been deprecated with message: The joomla/cache package is deprecated
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead. ![]() |
|||
251 | } |
||
252 | |||
253 | $keys = iterator_to_array($keys, false); |
||
254 | } |
||
255 | |||
256 | 5 | $items = $this->getItems($keys); |
|
257 | |||
258 | 5 | return $this->generateValues($default, $items); |
|
0 ignored issues
–
show
The return type of
return $this->generateValues($default, $items); (Generator ) is incompatible with the return type declared by the interface Psr\SimpleCache\CacheInterface::getMultiple of type Psr\SimpleCache\iterable .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Persists a set of key => value pairs in the cache, with an optional TTL. |
||
263 | * |
||
264 | * @param iterable $values A list of key => value pairs for a multiple-set operation. |
||
265 | * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
266 | * the driver supports TTL then the library may set a default value |
||
267 | * for it or let the driver take care of that. |
||
268 | * |
||
269 | * @return boolean True on success and false on failure. |
||
270 | * |
||
271 | * @since __DEPLOY_VERSION__ |
||
272 | * @throws InvalidArgumentException |
||
273 | */ |
||
274 | 10 | public function setMultiple($values, $ttl = null) |
|
275 | { |
||
276 | 10 | if (!is_array($values)) |
|
277 | { |
||
278 | if (!$values instanceof \Traversable) |
||
279 | { |
||
280 | throw new InvalidArgumentException('$values is neither an array nor Traversable'); |
||
0 ignored issues
–
show
The class
Joomla\Cache\Exception\InvalidArgumentException has been deprecated with message: The joomla/cache package is deprecated
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead. ![]() |
|||
281 | } |
||
282 | } |
||
283 | |||
284 | 10 | $keys = []; |
|
285 | 10 | $arrayValues = []; |
|
286 | |||
287 | 10 | foreach ($values as $key => $value) |
|
288 | { |
||
289 | 10 | if (is_int($key)) |
|
290 | { |
||
291 | $key = (string) $key; |
||
292 | } |
||
293 | |||
294 | 10 | $keys[] = $key; |
|
295 | 10 | $arrayValues[$key] = $value; |
|
296 | } |
||
297 | |||
298 | 10 | $items = $this->getItems($keys); |
|
299 | 10 | $itemSuccess = true; |
|
300 | |||
301 | /** @var $item CacheItemInterface */ |
||
302 | 10 | foreach ($items as $key => $item) |
|
303 | { |
||
304 | 10 | $item->set($arrayValues[$key]); |
|
305 | 10 | $item->expiresAfter($ttl); |
|
306 | |||
307 | 10 | $itemSuccess = $itemSuccess && $this->saveDeferred($item); |
|
308 | } |
||
309 | |||
310 | 10 | return $itemSuccess && $this->commit(); |
|
311 | } |
||
312 | |||
313 | /** |
||
314 | * Deletes multiple cache items in a single operation. |
||
315 | * |
||
316 | * @param iterable $keys A list of string-based keys to be deleted. |
||
317 | * |
||
318 | * @return boolean True if the items were successfully removed. False if there was an error. |
||
319 | * |
||
320 | * @since __DEPLOY_VERSION__ |
||
321 | * @throws InvalidArgumentException |
||
322 | */ |
||
323 | public function deleteMultiple($keys) |
||
324 | { |
||
325 | View Code Duplication | if (!is_array($keys)) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
326 | { |
||
327 | if (!$keys instanceof \Traversable) |
||
328 | { |
||
329 | throw new InvalidArgumentException('$keys is neither an array nor Traversable'); |
||
0 ignored issues
–
show
The class
Joomla\Cache\Exception\InvalidArgumentException has been deprecated with message: The joomla/cache package is deprecated
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead. ![]() |
|||
330 | } |
||
331 | |||
332 | $keys = iterator_to_array($keys, false); |
||
333 | } |
||
334 | |||
335 | return $this->deleteItems($keys); |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Determines whether an item is present in the cache. |
||
340 | * |
||
341 | * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
||
342 | * and not to be used within your live applications operations for get/set, as this method |
||
343 | * is subject to a race condition where your has() will return true and immediately after, |
||
344 | * another script can remove it making the state of your app out of date. |
||
345 | * |
||
346 | * @param string $key The cache item key. |
||
347 | * |
||
348 | * @return boolean |
||
349 | * |
||
350 | * @since __DEPLOY_VERSION__ |
||
351 | * @throws InvalidArgumentException |
||
352 | */ |
||
353 | 5 | public function has($key) |
|
354 | { |
||
355 | 5 | return $this->hasItem($key); |
|
356 | } |
||
357 | |||
358 | /** |
||
359 | * Converts a DateTime object from the cache item to the expiry time in seconds from the present |
||
360 | * |
||
361 | * @param HasExpirationDateInterface $item The cache item |
||
362 | * |
||
363 | * @return integer The time in seconds until expiry |
||
364 | * |
||
365 | * @since __DEPLOY_VERSION__ |
||
366 | */ |
||
367 | 24 | protected function convertItemExpiryToSeconds(HasExpirationDateInterface $item): int |
|
368 | { |
||
369 | 24 | return (int) $item->getExpiration()->getTimestamp() - time(); |
|
370 | } |
||
371 | |||
372 | /** |
||
373 | * Generate the values for the PSR-16 getMultiple method |
||
374 | * |
||
375 | * @param mixed $default Default value to return for keys that do not exist. |
||
376 | * @param array $items The items to process |
||
377 | * |
||
378 | * @return \Generator |
||
379 | * |
||
380 | * @since __DEPLOY_VERSION__ |
||
381 | */ |
||
382 | 5 | private function generateValues($default, array $items): \Generator |
|
383 | { |
||
384 | /** @var $item CacheItemInterface */ |
||
385 | 5 | foreach ($items as $key => $item) |
|
386 | { |
||
387 | 5 | if (!$item->isHit()) |
|
388 | { |
||
389 | 5 | yield $key => $default; |
|
390 | } |
||
391 | else |
||
392 | { |
||
393 | 5 | yield $key => $item->get(); |
|
394 | } |
||
395 | } |
||
396 | 5 | } |
|
397 | } |
||
398 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.