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 | /** |
||
4 | * |
||
5 | * This file is part of the Apix Project. |
||
6 | * |
||
7 | * (c) Franck Cassedanne <franck at ouarz.net> |
||
8 | * |
||
9 | * @license http://opensource.org/licenses/BSD-3-Clause New BSD License |
||
10 | * |
||
11 | */ |
||
12 | |||
13 | namespace Apix\Cache; |
||
14 | |||
15 | /** |
||
16 | * Base class provides the cache wrappers structure. |
||
17 | * |
||
18 | * @author Franck Cassedanne <franck at ouarz.net> |
||
19 | */ |
||
20 | abstract class AbstractCache implements Adapter |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Holds an injected adapter. |
||
25 | * @var object |
||
26 | */ |
||
27 | protected $adapter = null; |
||
28 | |||
29 | /** |
||
30 | * @var Serializer\Adapter |
||
31 | */ |
||
32 | protected $serializer; |
||
33 | |||
34 | /** |
||
35 | * Holds some generic default options. |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $options = array( |
||
39 | 'prefix_key' => 'apix-cache-key:', // prefix cache keys |
||
40 | 'prefix_tag' => 'apix-cache-tag:', // prefix cache tags |
||
41 | 'tag_enable' => true // wether to enable tagging |
||
42 | ); |
||
43 | |||
44 | /** |
||
45 | * Constructor use to set the adapter and dedicated options. |
||
46 | * |
||
47 | * @param object|null $adapter The adapter to set, generally an object. |
||
48 | * @param array|null $options The array of user options. |
||
49 | */ |
||
50 | 1881 | public function __construct($adapter=null, array $options=null) |
|
51 | { |
||
52 | 1881 | $this->adapter = $adapter; |
|
53 | 1881 | $this->setOptions($options); |
|
54 | 1881 | } |
|
55 | |||
56 | /** |
||
57 | * Sets and merges the options (overriding the default options). |
||
58 | * |
||
59 | * @param array|null $options The array of user options. |
||
60 | */ |
||
61 | 1881 | public function setOptions(array $options=null) |
|
62 | { |
||
63 | 1881 | if (null !== $options) { |
|
64 | 1881 | $this->options = $options+$this->options; |
|
65 | 1881 | } |
|
66 | 1881 | } |
|
67 | |||
68 | /** |
||
69 | * Returns the named option. |
||
70 | * |
||
71 | * @param string $key |
||
72 | * @return mixed |
||
73 | */ |
||
74 | 750 | public function getOption($key) |
|
75 | { |
||
76 | 750 | if (!isset($this->options[$key])) { |
|
77 | 17 | throw new PsrCache\InvalidArgumentException( |
|
78 | 17 | sprintf('Invalid option "%s"', $key) |
|
79 | 17 | ); |
|
80 | } |
||
81 | |||
82 | 733 | return $this->options[$key]; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Sets the named option. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * @param mixed $value |
||
90 | */ |
||
91 | 34 | public function setOption($key, $value) |
|
92 | { |
||
93 | 34 | return $this->options[$key] = $value; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Returns a prefixed and sanitased cache id. |
||
98 | * |
||
99 | * @param string $key The base key to prefix. |
||
100 | * @return string |
||
101 | */ |
||
102 | 1393 | public function mapKey($key) |
|
103 | { |
||
104 | 1393 | return $this->sanitise($this->options['prefix_key'] . $key); |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Returns a prefixed and sanitased cache tag. |
||
109 | * |
||
110 | * @param string $tag The base tag to prefix. |
||
111 | * @return string |
||
112 | */ |
||
113 | 574 | public function mapTag($tag) |
|
114 | { |
||
115 | 574 | return $this->sanitise($this->options['prefix_tag'] . $tag); |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Returns a sanitased string for keying/tagging purpose. |
||
120 | * |
||
121 | * @param string $key The string to sanitise. |
||
122 | * @return string |
||
123 | */ |
||
124 | 1473 | public function sanitise($key) |
|
125 | { |
||
126 | 1473 | return $key; |
|
127 | // return str_replace(array('/', '\\', ' '), '_', $key); |
||
0 ignored issues
–
show
|
|||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Gets the injected adapter. |
||
132 | * |
||
133 | * @return object |
||
134 | */ |
||
135 | 83 | public function getAdapter() |
|
136 | { |
||
137 | 83 | return $this->adapter; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Sets the serializer. |
||
142 | * |
||
143 | * @param string $name |
||
144 | */ |
||
145 | 94 | public function setSerializer($name) |
|
146 | { |
||
147 | 94 | if (null === $name) { |
|
148 | 17 | $this->serializer = null; |
|
149 | 17 | } else { |
|
150 | 94 | $classname = __NAMESPACE__ . '\Serializer\\'; |
|
151 | 94 | $classname .= ucfirst(strtolower($name)); |
|
152 | 94 | $this->serializer = new $classname(); |
|
153 | } |
||
154 | 94 | } |
|
155 | |||
156 | /** |
||
157 | * Gets the serializer. |
||
158 | * |
||
159 | * @return Serializer\Adapter |
||
160 | */ |
||
161 | 83 | public function getSerializer() |
|
162 | { |
||
163 | 83 | return $this->serializer; |
|
164 | } |
||
165 | |||
166 | /** |
||
167 | * Retrieves the cache content for the given key or the keys for a given tag. |
||
168 | * |
||
169 | * @param string $key The cache id to retrieve. |
||
170 | * @param string $type The type of the key (either 'key' or 'tag'). |
||
171 | * @return mixed|null Returns the cached data or null if not set. |
||
172 | */ |
||
173 | 379 | public function load($key, $type='key') |
|
174 | { |
||
175 | 379 | return $type == 'key' ? $this->loadKey($key) : $this->loadTag($key); |
|
176 | } |
||
177 | |||
178 | /** |
||
179 | * Returns the given string without the given prefix. |
||
180 | * |
||
181 | * @param string $str The subject string |
||
182 | * @param string $prefix The prefix to remove |
||
183 | * @return string |
||
184 | */ |
||
185 | 697 | public function removePrefix($str, $prefix) |
|
186 | { |
||
187 | 697 | return substr($str, 0, strlen($prefix)) == $prefix |
|
188 | 697 | ? substr($str, strlen($prefix)) |
|
189 | 697 | : $str; |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * Returns the given string without the internal key prefix. |
||
194 | * |
||
195 | * @param string $str |
||
196 | * @return string |
||
197 | */ |
||
198 | 629 | public function removePrefixKey($str) |
|
199 | { |
||
200 | 629 | return $this->removePrefix($str, $this->options['prefix_key']); |
|
201 | } |
||
202 | |||
203 | /** |
||
204 | * Returns the given string without the internal tag prefix. |
||
205 | * |
||
206 | * @param string $str |
||
207 | * @return string |
||
208 | */ |
||
209 | 68 | public function removePrefixTag($str) |
|
210 | { |
||
211 | 68 | return $this->removePrefix($str, $this->options['prefix_tag']); |
|
212 | } |
||
213 | |||
214 | } |
||
215 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.