Skip to content

Commit 54454ba

Browse files
author
Drak
committed
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.
1 parent 1103ca8 commit 54454ba

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Symfony/Component/HttpFoundation/ParameterBag.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,25 @@ public function getInt($key, $default = 0, $deep = false)
242242
{
243243
return (int) $this->get($key, $default, $deep);
244244
}
245+
246+
/**
247+
* Filter key.
248+
*
249+
* @param string $key Key.
250+
* @param mixed $default Default = null.
251+
* @param boolean $deep Default = false.
252+
* @param integer $filter FILTER_* constant.
253+
* @param array $options Fitler options.
254+
*
255+
* @return mixed
256+
*/
257+
public function filter($key, $default = null, $deep = false, $filter=FILTER_DEFAULT, array $options=array())
258+
{
259+
$value = $this->get($key, $default, $deep);
260+
if (is_array($value)) {
261+
$options['flags'] = FILTER_REQUIRE_ARRAY;
262+
}
263+
264+
return filter_var($value, $filter, $options);
265+
}
245266
}

0 commit comments

Comments
 (0)