本文整理汇总了PHP中Symfony\Component\HttpFoundation\ParameterBag::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP ParameterBag::filter方法的具体用法?PHP ParameterBag::filter怎么用?PHP ParameterBag::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\ParameterBag
的用法示例。
在下文中一共展示了ParameterBag::filter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
* Filter key.
* @deprecated as of Core 1.4.0
* @see \Symfony\Component\HttpFoundation\ParameterBag::filter
*
* @param string $key Key.
* @param mixed $default Default = null.
* @param bool $deep Default = false.
* @param int $filter FILTER_* constant.
* @param mixed $options Filter options.
*
* @see http://php.net/manual/en/function.filter-var.php
*
* @return mixed
*/
public function filter($key, $default = null, $deep = false, $filter = FILTER_DEFAULT, $options = array())
{
if (func_num_args() > 2) {
if (is_bool(func_get_arg(2))) {
// usage is compatible with normal ParameterBag
$deep = func_get_arg(2);
$filter = func_num_args() >= 4 && func_get_arg(3) !== false ? func_get_arg(3) : FILTER_DEFAULT;
$options = func_num_args() == 5 && func_get_arg(4) !== false ? func_get_arg(4) : array();
} else {
// using old signature - third param exists and is a constant, not a bool
LogUtil::log('The method signature for filter() has changed. See \\Symfony\\Component\\HttpFoundation\\ParameterBag::filter().', E_USER_DEPRECATED);
$filter = func_num_args() >= 3 && func_get_arg(2) !== false ? func_get_arg(2) : FILTER_DEFAULT;
$options = func_num_args() >= 4 && func_get_arg(3) !== false ? func_get_arg(3) : array();
}
}
return parent::filter($key, $default, $filter, $options, $deep);
}
示例2: testFilter
public function testFilter()
{
$bag = new ParameterBag(array('digits' => '0123ab', 'email' => 'example@example.com', 'url' => 'http://example.com/foo', 'dec' => '256', 'hex' => '0x100', 'array' => array('bang')));
$this->assertEmpty($bag->filter('nokey'), '->filter() should return empty by default if no key is found');
$this->assertEquals('0123', $bag->filter('digits', '', false, FILTER_SANITIZE_NUMBER_INT), '->filter() gets a value of parameter as integer filtering out invalid characters');
$this->assertEquals('example@example.com', $bag->filter('email', '', false, FILTER_VALIDATE_EMAIL), '->filter() gets a value of parameter as email');
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', false, FILTER_VALIDATE_URL, array('flags' => FILTER_FLAG_PATH_REQUIRED)), '->filter() gets a value of parameter as URL with a path');
// This test is repeated for code-coverage
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', false, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED), '->filter() gets a value of parameter as URL with a path');
$this->assertFalse($bag->filter('dec', '', false, FILTER_VALIDATE_INT, array('flags' => FILTER_FLAG_ALLOW_HEX, 'options' => array('min_range' => 1, 'max_range' => 0xff))), '->filter() gets a value of parameter as integer between boundaries');
$this->assertFalse($bag->filter('hex', '', false, FILTER_VALIDATE_INT, array('flags' => FILTER_FLAG_ALLOW_HEX, 'options' => array('min_range' => 1, 'max_range' => 0xff))), '->filter() gets a value of parameter as integer between boundaries');
$this->assertEquals(array('bang'), $bag->filter('array', '', false), '->filter() gets a value of parameter as an array');
}