/**
* Returns a parameter by name.
*
- * Note: Finding deep items is deprecated since version 2.8, to be removed in 3.0.
- *
* @param string $key The key
* @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
*
* @return mixed
- *
- * @throws \InvalidArgumentException
*/
- public function get($key, $default = null, $deep = false)
+ public function get($key, $default = null)
{
- if ($deep) {
- @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);
- }
-
- if (!$deep || false === $pos = strpos($key, '[')) {
- return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
- }
-
- $root = substr($key, 0, $pos);
- if (!array_key_exists($root, $this->parameters)) {
- return $default;
- }
-
- $value = $this->parameters[$root];
- $currentKey = null;
- for ($i = $pos, $c = strlen($key); $i < $c; ++$i) {
- $char = $key[$i];
-
- if ('[' === $char) {
- if (null !== $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
- }
-
- $currentKey = '';
- } elseif (']' === $char) {
- if (null === $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
- }
-
- if (!is_array($value) || !array_key_exists($currentKey, $value)) {
- return $default;
- }
-
- $value = $value[$currentKey];
- $currentKey = null;
- } else {
- if (null === $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
- }
-
- $currentKey .= $char;
- }
- }
-
- if (null !== $currentKey) {
- throw new \InvalidArgumentException('Malformed path. Path must end with "]".');
- }
-
- return $value;
+ return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
}
/**
*
* @param string $key The parameter key
* @param string $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*/
- public function getAlpha($key, $default = '', $deep = false)
+ public function getAlpha($key, $default = '')
{
- return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
+ return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
}
/**
*
* @param string $key The parameter key
* @param string $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*/
- public function getAlnum($key, $default = '', $deep = false)
+ public function getAlnum($key, $default = '')
{
- return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
+ return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
}
/**
*
* @param string $key The parameter key
* @param string $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*/
- public function getDigits($key, $default = '', $deep = false)
+ public function getDigits($key, $default = '')
{
// we need to remove - and + because they're allowed in the filter
- return str_replace(array('-', '+'), '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT, array(), $deep));
+ return str_replace(array('-', '+'), '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT));
}
/**
*
* @param string $key The parameter key
* @param int $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
*
* @return int The filtered value
*/
- public function getInt($key, $default = 0, $deep = false)
+ public function getInt($key, $default = 0)
{
- return (int) $this->get($key, $default, $deep);
+ return (int) $this->get($key, $default);
}
/**
*
* @param string $key The parameter key
* @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
*
* @return bool The filtered value
*/
- public function getBoolean($key, $default = false, $deep = false)
+ public function getBoolean($key, $default = false)
{
- return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN, array(), $deep);
+ return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN);
}
/**
* @param mixed $default Default = null
* @param int $filter FILTER_* constant
* @param mixed $options Filter options
- * @param bool $deep Default = false
*
* @see http://php.net/manual/en/function.filter-var.php
*
* @return mixed
*/
- public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array(), $deep = false)
+ public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array())
{
- static $filters = null;
-
- if (null === $filters) {
- foreach (filter_list() as $tmp) {
- $filters[filter_id($tmp)] = 1;
- }
- }
- if (is_bool($filter) || !isset($filters[$filter]) || is_array($deep)) {
- @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);
- $tmp = $deep;
- $deep = $filter;
- $filter = $options;
- $options = $tmp;
- }
-
- $value = $this->get($key, $default, $deep);
+ $value = $this->get($key, $default);
// Always turn $options into an array - this allows filter_var option shortcuts.
if (!is_array($options) && $options) {