Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ParameterBag.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpFoundation;
013
014 /**
015 * ParameterBag is a container for key/value pairs.
016 *
017 * @author Fabien Potencier <fabien@symfony.com>
018 */
019 class ParameterBag implements \IteratorAggregate, \Countable
020 {
021 /**
022 * Parameter storage.
023 *
024 * @var array
025 */
026 protected $parameters;
027
028 /**
029 * Constructor.
030 *
031 * @param array $parameters An array of parameters
032 */
033 public function __construct(array $parameters = array())
034 {
035 $this->parameters = $parameters;
036 }
037
038 /**
039 * Returns the parameters.
040 *
041 * @return array An array of parameters
042 */
043 public function all()
044 {
045 return $this->parameters;
046 }
047
048 /**
049 * Returns the parameter keys.
050 *
051 * @return array An array of parameter keys
052 */
053 public function keys()
054 {
055 return array_keys($this->parameters);
056 }
057
058 /**
059 * Replaces the current parameters by a new set.
060 *
061 * @param array $parameters An array of parameters
062 */
063 public function replace(array $parameters = array())
064 {
065 $this->parameters = $parameters;
066 }
067
068 /**
069 * Adds parameters.
070 *
071 * @param array $parameters An array of parameters
072 */
073 public function add(array $parameters = array())
074 {
075 $this->parameters = array_replace($this->parameters, $parameters);
076 }
077
078 /**
079 * Returns a parameter by name.
080 *
081 * Note: Finding deep items is deprecated since version 2.8, to be removed in 3.0.
082 *
083 * @param string $key The key
084 * @param mixed $default The default value if the parameter key does not exist
085 * @param bool $deep If true, a path like foo[bar] will find deeper items
086 *
087 * @return mixed
088 *
089 * @throws \InvalidArgumentException
090 */
091 public function get($key, $default = null, $deep = false)
092 {
093 if ($deep) {
094 @trigger_error('Using paths to find deeper items in '.__METHOD__.' is deprecated since version 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.', E_USER_DEPRECATED);
095 }
096
097 if (!$deep || false === $pos = strpos($key, '[')) {
098 return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
099 }
100
101 $root = substr($key, 0, $pos);
102 if (!array_key_exists($root, $this->parameters)) {
103 return $default;
104 }
105
106 $value = $this->parameters[$root];
107 $currentKey = null;
108 for ($i = $pos, $c = strlen($key); $i < $c; ++$i) {
109 $char = $key[$i];
110
111 if ('[' === $char) {
112 if (null !== $currentKey) {
113 throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
114 }
115
116 $currentKey = '';
117 } elseif (']' === $char) {
118 if (null === $currentKey) {
119 throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
120 }
121
122 if (!is_array($value) || !array_key_exists($currentKey, $value)) {
123 return $default;
124 }
125
126 $value = $value[$currentKey];
127 $currentKey = null;
128 } else {
129 if (null === $currentKey) {
130 throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
131 }
132
133 $currentKey .= $char;
134 }
135 }
136
137 if (null !== $currentKey) {
138 throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
139 }
140
141 return $value;
142 }
143
144 /**
145 * Sets a parameter by name.
146 *
147 * @param string $key The key
148 * @param mixed $value The value
149 */
150 public function set($key, $value)
151 {
152 $this->parameters[$key] = $value;
153 }
154
155 /**
156 * Returns true if the parameter is defined.
157 *
158 * @param string $key The key
159 *
160 * @return bool true if the parameter exists, false otherwise
161 */
162 public function has($key)
163 {
164 return array_key_exists($key, $this->parameters);
165 }
166
167 /**
168 * Removes a parameter.
169 *
170 * @param string $key The key
171 */
172 public function remove($key)
173 {
174 unset($this->parameters[$key]);
175 }
176
177 /**
178 * Returns the alphabetic characters of the parameter value.
179 *
180 * @param string $key The parameter key
181 * @param string $default The default value if the parameter key does not exist
182 * @param bool $deep If true, a path like foo[bar] will find deeper items
183 *
184 * @return string The filtered value
185 */
186 public function getAlpha($key, $default = '', $deep = false)
187 {
188 return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
189 }
190
191 /**
192 * Returns the alphabetic characters and digits of the parameter value.
193 *
194 * @param string $key The parameter key
195 * @param string $default The default value if the parameter key does not exist
196 * @param bool $deep If true, a path like foo[bar] will find deeper items
197 *
198 * @return string The filtered value
199 */
200 public function getAlnum($key, $default = '', $deep = false)
201 {
202 return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
203 }
204
205 /**
206 * Returns the digits of the parameter value.
207 *
208 * @param string $key The parameter key
209 * @param string $default The default value if the parameter key does not exist
210 * @param bool $deep If true, a path like foo[bar] will find deeper items
211 *
212 * @return string The filtered value
213 */
214 public function getDigits($key, $default = '', $deep = false)
215 {
216 // we need to remove - and + because they're allowed in the filter
217 return str_replace(array('-', '+'), '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT, array(), $deep));
218 }
219
220 /**
221 * Returns the parameter value converted to integer.
222 *
223 * @param string $key The parameter key
224 * @param int $default The default value if the parameter key does not exist
225 * @param bool $deep If true, a path like foo[bar] will find deeper items
226 *
227 * @return int The filtered value
228 */
229 public function getInt($key, $default = 0, $deep = false)
230 {
231 return (int) $this->get($key, $default, $deep);
232 }
233
234 /**
235 * Returns the parameter value converted to boolean.
236 *
237 * @param string $key The parameter key
238 * @param mixed $default The default value if the parameter key does not exist
239 * @param bool $deep If true, a path like foo[bar] will find deeper items
240 *
241 * @return bool The filtered value
242 */
243 public function getBoolean($key, $default = false, $deep = false)
244 {
245 return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN, array(), $deep);
246 }
247
248 /**
249 * Filter key.
250 *
251 * @param string $key Key
252 * @param mixed $default Default = null
253 * @param int $filter FILTER_* constant
254 * @param mixed $options Filter options
255 * @param bool $deep Default = false
256 *
257 * @see http://php.net/manual/en/function.filter-var.php
258 *
259 * @return mixed
260 */
261 public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array(), $deep = false)
262 {
263 static $filters = null;
264
265 if (null === $filters) {
266 foreach (filter_list() as $tmp) {
267 $filters[filter_id($tmp)] = 1;
268 }
269 }
270 if (is_bool($filter) || !isset($filters[$filter]) || is_array($deep)) {
271 @trigger_error('Passing the $deep boolean as 3rd argument to the '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Remove it altogether as the $deep argument will be removed in 3.0.', E_USER_DEPRECATED);
272 $tmp = $deep;
273 $deep = $filter;
274 $filter = $options;
275 $options = $tmp;
276 }
277
278 $value = $this->get($key, $default, $deep);
279
280 // Always turn $options into an array - this allows filter_var option shortcuts.
281 if (!is_array($options) && $options) {
282 $options = array('flags' => $options);
283 }
284
285 // Add a convenience check for arrays.
286 if (is_array($value) && !isset($options['flags'])) {
287 $options['flags'] = FILTER_REQUIRE_ARRAY;
288 }
289
290 return filter_var($value, $filter, $options);
291 }
292
293 /**
294 * Returns an iterator for parameters.
295 *
296 * @return \ArrayIterator An \ArrayIterator instance
297 */
298 public function getIterator()
299 {
300 return new \ArrayIterator($this->parameters);
301 }
302
303 /**
304 * Returns the number of parameters.
305 *
306 * @return int The number of parameters
307 */
308 public function count()
309 {
310 return count($this->parameters);
311 }
312 }
313