Open Journal Systems  3.3.0
lib/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 {
26  protected $parameters;
27 
33  public function __construct(array $parameters = array())
34  {
35  $this->parameters = $parameters;
36  }
37 
43  public function all()
44  {
45  return $this->parameters;
46  }
47 
53  public function keys()
54  {
55  return array_keys($this->parameters);
56  }
57 
63  public function replace(array $parameters = array())
64  {
65  $this->parameters = $parameters;
66  }
67 
73  public function add(array $parameters = array())
74  {
75  $this->parameters = array_replace($this->parameters, $parameters);
76  }
77 
86  public function get($key, $default = null)
87  {
88  return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
89  }
90 
97  public function set($key, $value)
98  {
99  $this->parameters[$key] = $value;
100  }
101 
109  public function has($key)
110  {
111  return array_key_exists($key, $this->parameters);
112  }
113 
119  public function remove($key)
120  {
121  unset($this->parameters[$key]);
122  }
123 
132  public function getAlpha($key, $default = '')
133  {
134  return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
135  }
136 
145  public function getAlnum($key, $default = '')
146  {
147  return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
148  }
149 
158  public function getDigits($key, $default = '')
159  {
160  // we need to remove - and + because they're allowed in the filter
161  return str_replace(array('-', '+'), '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT));
162  }
163 
172  public function getInt($key, $default = 0)
173  {
174  return (int) $this->get($key, $default);
175  }
176 
185  public function getBoolean($key, $default = false)
186  {
187  return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN);
188  }
189 
202  public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array())
203  {
204  $value = $this->get($key, $default);
205 
206  // Always turn $options into an array - this allows filter_var option shortcuts.
207  if (!is_array($options) && $options) {
208  $options = array('flags' => $options);
209  }
210 
211  // Add a convenience check for arrays.
212  if (is_array($value) && !isset($options['flags'])) {
213  $options['flags'] = FILTER_REQUIRE_ARRAY;
214  }
215 
216  return filter_var($value, $filter, $options);
217  }
218 
224  public function getIterator()
225  {
226  return new \ArrayIterator($this->parameters);
227  }
228 
234  public function count()
235  {
236  return count($this->parameters);
237  }
238 }
Symfony\Component\HttpFoundation\ParameterBag\getInt
getInt($key, $default=0)
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:175
Symfony\Component\HttpFoundation\ParameterBag\getAlpha
getAlpha($key, $default='')
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:135
Symfony\Component\HttpFoundation\ParameterBag\$parameters
$parameters
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:29
Symfony\Component\HttpFoundation\ParameterBag\has
has($key)
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:112
Symfony\Component\HttpFoundation\ParameterBag\all
all()
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:46
Symfony\Component\HttpFoundation\ParameterBag\getBoolean
getBoolean($key, $default=false)
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:188
Symfony\Component\HttpFoundation\ParameterBag\getIterator
getIterator()
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:227
Symfony\Component\HttpFoundation\ParameterBag\keys
keys()
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:56
Symfony\Component\HttpFoundation\ParameterBag\getDigits
getDigits($key, $default='')
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:161
Symfony\Component\HttpFoundation\ParameterBag\getAlnum
getAlnum($key, $default='')
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:148
Symfony\Component\HttpFoundation\ParameterBag\count
count()
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:237
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
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:19
Symfony\Component\HttpFoundation\ParameterBag\__construct
__construct(array $parameters=array())
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:36
Symfony\Component\HttpFoundation\ParameterBag\replace
replace(array $parameters=array())
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:66
Symfony\Component\HttpFoundation
Definition: lib/vendor/symfony/http-foundation/AcceptHeader.php:12
Symfony\Component\HttpFoundation\ParameterBag\add
add(array $parameters=array())
Definition: lib/vendor/symfony/http-foundation/ParameterBag.php:76