Added generic filtering to ParameterBag.
Adds filtering convenience using PHP's filter_var() e.g. `$request->get->filter($key, '', false, FITLER_SANITIZE_STRING);` See http://php.net/manual/en/filter.filters.php for capabilities.
This commit is contained in:
parent
1103ca8185
commit
54454ba4aa
@ -242,4 +242,25 @@ class ParameterBag
|
||||
{
|
||||
return (int) $this->get($key, $default, $deep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter key.
|
||||
*
|
||||
* @param string $key Key.
|
||||
* @param mixed $default Default = null.
|
||||
* @param boolean $deep Default = false.
|
||||
* @param integer $filter FILTER_* constant.
|
||||
* @param array $options Fitler options.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter($key, $default = null, $deep = false, $filter=FILTER_DEFAULT, array $options=array())
|
||||
{
|
||||
$value = $this->get($key, $default, $deep);
|
||||
if (is_array($value)) {
|
||||
$options['flags'] = FILTER_REQUIRE_ARRAY;
|
||||
}
|
||||
|
||||
return filter_var($value, $filter, $options);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user