Open Journal Systems  3.3.0
vendor/symfony/http-foundation/ParameterBag.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
19 class ParameterBag implements \IteratorAggregate, \Countable
20 {
24  protected $parameters;
25 
26  public function __construct(array $parameters = [])
27  {
28  $this->parameters = $parameters;
29  }
30 
36  public function all()
37  {
38  return $this->parameters;
39  }
40 
46  public function keys()
47  {
48  return array_keys($this->parameters);
49  }
50 
54  public function replace(array $parameters = [])
55  {
56  $this->parameters = $parameters;
57  }
58 
62  public function add(array $parameters = [])
63  {
64  $this->parameters = array_replace($this->parameters, $parameters);
65  }
66 
75  public function get($key, $default = null)
76  {
77  return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
78  }
79 
86  public function set($key, $value)
87  {
88  $this->parameters[$key] = $value;
89  }
90 
98  public function has($key)
99  {
100  return \array_key_exists($key, $this->parameters);
101  }
102 
108  public function remove($key)
109  {
110  unset($this->parameters[$key]);
111  }
112 
121  public function getAlpha($key, $default = '')
122  {
123  return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
124  }
125 
134  public function getAlnum($key, $default = '')
135  {
136  return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
137  }
138 
147  public function getDigits($key, $default = '')
148  {
149  // we need to remove - and + because they're allowed in the filter
150  return str_replace(['-', '+'], '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT));
151  }
152 
161  public function getInt($key, $default = 0)
162  {
163  return (int) $this->get($key, $default);
164  }
165 
174  public function getBoolean($key, $default = false)
175  {
176  return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN);
177  }
178 
191  public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = [])
192  {
193  $value = $this->get($key, $default);
194 
195  // Always turn $options into an array - this allows filter_var option shortcuts.
196  if (!\is_array($options) && $options) {
197  $options = ['flags' => $options];
198  }
199 
200  // Add a convenience check for arrays.
201  if (\is_array($value) && !isset($options['flags'])) {
202  $options['flags'] = FILTER_REQUIRE_ARRAY;
203  }
204 
205  return filter_var($value, $filter, $options);
206  }
207 
213  public function getIterator()
214  {
215  return new \ArrayIterator($this->parameters);
216  }
217 
223  public function count()
224  {
225  return \count($this->parameters);
226  }
227 }
Symfony\Component\HttpFoundation\ParameterBag\__construct
__construct(array $parameters=[])
Definition: vendor/symfony/http-foundation/ParameterBag.php:26
Symfony\Component\HttpFoundation\ParameterBag\filter
filter($key, $default=null, $filter=FILTER_DEFAULT, $options=[])
Definition: vendor/symfony/http-foundation/ParameterBag.php:191
Symfony\Component\HttpFoundation\ParameterBag\getInt
getInt($key, $default=0)
Definition: vendor/symfony/http-foundation/ParameterBag.php:161
Symfony\Component\HttpFoundation\ParameterBag\getAlpha
getAlpha($key, $default='')
Definition: vendor/symfony/http-foundation/ParameterBag.php:121
Symfony\Component\HttpFoundation\ParameterBag\$parameters
$parameters
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:29
Symfony\Component\HttpFoundation\ParameterBag\has
has($key)
Definition: vendor/symfony/http-foundation/ParameterBag.php:98
Symfony\Component\HttpFoundation\ParameterBag\all
all()
Definition: vendor/symfony/http-foundation/ParameterBag.php:36
Symfony\Component\HttpFoundation\ParameterBag\getBoolean
getBoolean($key, $default=false)
Definition: vendor/symfony/http-foundation/ParameterBag.php:174
Symfony\Component\HttpFoundation\ParameterBag\getIterator
getIterator()
Definition: vendor/symfony/http-foundation/ParameterBag.php:213
Symfony\Component\HttpFoundation\ParameterBag\keys
keys()
Definition: vendor/symfony/http-foundation/ParameterBag.php:46
Symfony\Component\HttpFoundation\ParameterBag\getDigits
getDigits($key, $default='')
Definition: vendor/symfony/http-foundation/ParameterBag.php:147
Symfony\Component\HttpFoundation\ParameterBag\getAlnum
getAlnum($key, $default='')
Definition: vendor/symfony/http-foundation/ParameterBag.php:134
Symfony\Component\HttpFoundation\ParameterBag\count
count()
Definition: vendor/symfony/http-foundation/ParameterBag.php:223
Symfony\Component\HttpFoundation\ParameterBag\filter
filter($key, $default=null, $filter=FILTER_DEFAULT, $options=array())
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:205
Symfony\Component\HttpFoundation\ParameterBag\replace
replace(array $parameters=[])
Definition: vendor/symfony/http-foundation/ParameterBag.php:54
Symfony\Component\HttpFoundation\ParameterBag\add
add(array $parameters=[])
Definition: vendor/symfony/http-foundation/ParameterBag.php:62
Symfony\Component\HttpFoundation
Definition: lib/vendor/symfony/http-foundation/AcceptHeader.php:12