10000 [HttpFoundation] Deprecate $deep parameter on ParameterBag · symfony/symfony@f4f082e · GitHub
[go: up one dir, main page]

Skip to content

Commit f4f082e

Browse files
[HttpFoundation] Deprecate $deep parameter on ParameterBag
1 parent b296910 commit f4f082e

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

src/Symfony/Component/HttpFoundation/ParameterBag.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function add(array $parameters = array())
9090
*/
9191
public function get($key, $default = null, $deep = false)
9292
{
93-
if (true === $deep) {
93+
if ($deep) {
9494
@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);
9595
}
9696

@@ -214,7 +214,7 @@ public function getAlnum($key, $default = '', $deep = false)
214214
public function getDigits($key, $default = '', $deep = false)
215215
{
216216
// we need to remove - and + because they're allowed in the filter
217-
return str_replace(array('-', '+'), '', $this->filter($key, $default, $deep, FILTER_SANITIZE_NUMBER_INT));
217+
return str_replace(array('-', '+'), '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT, array(), $deep));
218218
}
219219

220220
/**
@@ -242,24 +242,39 @@ public function getInt($key, $default = 0, $deep = false)
242242
*/
243243
public function getBoolean($key, $default = false, $deep = false)
244244
{
245-
return $this->filter($key, $default, $deep, FILTER_VALIDATE_BOOLEAN);
245+
return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN, array(), $deep);
246246
}
247247

248248
/**
249249
* Filter key.
250250
*
251251
* @param string $key Key.
252252
* @param mixed $default Default = null.
253-
* @param bool $deep Default = false.
254253
* @param int $filter FILTER_* constant.
255254
* @param mixed $options Filter options.
255+
* @param bool $deep Default = false.
256256
*
257257
* @see http://php.net/manual/en/function.filter-var.php
258258
*
259259
* @return mixed
260260
*/
261-
public function filter($key, $default = null, $deep = false, $filter = FILTER_DEFAULT, $options = array())
261+
public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array(), $deep = false)
262262
{
263+
static $filters = null;
264+
265+
if (null === $filters) {
266+
foreach (filter_list() as $tmp) {
267+
$filters[filter_id($tmp)] = 1;
268+
}
269+
}
270+
if (is_bool($filter) || !isset($filters[$filter]) || is_array($deep)) {
271+
@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_ERROR);
272+
$tmp = $deep;
273+
$deep = $filter;
274+
$filter = $options;
275+
$options = $tmp;
276+
}
277+
263278
$value = $this->get($key, $default, $deep);
264279

265280
// Always turn $options into an array - this allows filter_var option shortcuts.

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ public static function getHttpMethodParameterOverride()
724724
*/
725725
public function get($key, $default = null, $deep = false)
726726
{
727-
if (true === $deep) {
727+
if ($deep) {
728728
@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);
729729
}
730730

src/Symfony/Component/HttpFoundation/Tests/ParameterBagTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,26 @@ public function testFilter()
172172

173173
$this->assertEmpty($bag->filter('nokey'), '->filter() should return empty by default if no key is found');
174174

175-
$this->assertEquals('0123', $bag->filter('digits', '', false, FILTER_SANITIZE_NUMBER_INT), '->filter() gets a value of parameter as integer filtering out invalid characters');
175+
$this->assertEquals('0123', $bag->filter('digits', '', FILTER_SANITIZE_NUMBER_INT), '->filter() gets a value of parameter as integer filtering out invalid characters');
176176

177-
$this->assertEquals('example@example.com', $bag->filter('email', '', false, FILTER_VALIDATE_EMAIL), '->filter() gets a value of parameter as email');
177+
$this->assertEquals('example@example.com', $bag->filter('email', '', FILTER_VALIDATE_EMAIL), '->filter() gets a value of parameter as email');
178178

179-
$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');
179+
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', FILTER_VALIDATE_URL, array('flags' => FILTER_FLAG_PATH_REQUIRED)), '->filter() gets a value of parameter as URL with a path');
180180

181181
// This test is repeated for code-coverage
182-
$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');
182+
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED), '->filter() gets a value of parameter as URL with a path');
183183

184-
$this->assertFalse($bag->filter('dec', '', false, FILTER_VALIDATE_INT, array(
184+
$this->assertFalse($bag->filter('dec', '', FILTER_VALIDATE_INT, array(
185185
'flags' => FILTER_FLAG_ALLOW_HEX,
186186
'options' => array('min_range' => 1, 'max_range' => 0xff),
187187
)), '->filter() gets a value of parameter as integer between boundaries');
188188

189-
$this->assertFalse($bag->filter('hex', '', false, FILTER_VALIDATE_INT, array(
189+
$this->assertFalse($bag->filter('hex', '', FILTER_VALIDATE_INT, array(
190190
'flags' => FILTER_FLAG_ALLOW_HEX,
191191
'options' => array('min_range' => 1, 'max_range' => 0xff),
192192
)), '->filter() gets a value of parameter as integer between boundaries');
193193

194-
$this->assertEquals(array('bang'), $bag->filter('array', '', false), '->filter() gets a value of parameter as an array');
194+
$this->assertEquals(array('bang'), $bag->filter('array', ''), '->filter() gets a value of parameter as an array');
195195
}
196196

197197
public function testGetIterator()

0 commit comments

Comments
 (0)
0