8000 [HttpFoundation] removed the ParameterBag::get() deep argument · symfony/symfony@317f7b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 317f7b4

Browse files
committed
[HttpFoundation] removed the ParameterBag::get() deep argument
1 parent ed610df commit 317f7b4

File tree

4 files changed

+9
-102
lines changed

4 files changed

+9
-102
lines changed

src/Symfony/Component/HttpFoundation/ParameterBag.php

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -78,67 +78,16 @@ public function add(array $parameters = array())
7878
/**
7979
* Returns a parameter by name.
8080
*
81-
* Note: Finding deep items is deprecated since version 2.8, to be removed in 3.0.
82-
*
8381
* @param string $key The key
8482
* @param mixed $default The default value if the parameter key does not exist
85-
* @param bool $deep If true, a path like foo[bar] will find deeper items
8683
*
8784
* @return mixed
8885
*
8986
* @throws \InvalidArgumentException
9087
*/
91-
public function get($key, $default = null, $deep = false)
88+
public function get($key, $default = null)
9289
{
93-
if (true === $deep) {
94-
@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);
95-
}
96-
97-
if (!$deep || false === $pos = strpos($key, '[')) {
98-
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
99-
}
100-
101-
$root = substr($key, 0, $pos);
102-
if (!array_key_exists($root, $this->parameters)) {
103-
return $default;
104-
}
105-
106-
$value = $this->parameters[$root];
107-
$currentKey = null;
108-
for ($i = $pos, $c = strlen($key); $i < $c; ++$i) {
109-
$char = $key[$i];
110-
111-
if ('[' === $char) {
112-
if (null !== $currentKey) {
113-
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
114-
}
115-
116-
$currentKey = '';
117-
} elseif (']' === $char) {
118-
if (null === $currentKey) {
119-
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
120-
}
121-
122-
if (!is_array($value) || !array_key_exists($currentKey, $value)) {
123-
return $default;
124-
}
125-
126-
$value = $value[$currentKey];
127-
$currentKey = null;
128-
} else {
129-
if (null === $currentKey) {
130-
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
131-
}
132-
133-
$currentKey .= $char;
134-
}
135-
}
136-
137-
if (null !== $currentKey) {
138-
throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
139-
}
140-
141-
return $value;
90+
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
14291
}
14392

14493
/**

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -714,29 +714,22 @@ public static function getHttpMethodParameterOverride()
714714
* It is better to explicitly get request parameters from the appropriate
715715
* public property instead (query, attributes, request).
716716
*
717-
* Note: Finding deep items is deprecated since version 2.8, to be removed in 3.0.
718-
*
719717
* @param string $key the key
720718
* @param mixed $default the default value
721-
* @param bool $deep is parameter deep in multidimensional array
722719
*
723720
* @return mixed
724721
*/
725-
public function get($key, $default = null, $deep = false)
722+
public function get($key, $default = null)
726723
{
727-
if (true === $deep) {
728-
@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);
729-
}
730-
731-
if ($this !== $result = $this->query->get($key, $this, $deep)) {
724+
if ($this !== $result = $this->query->get($key, $this)) {
732725
return $result;
733726
}
734727

735-
if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
728+
if ($this !== $result = $this->attributes->get($key, $this)) {
736729
return $result;
737730
}
738731

739-
if ($this !== $result = $this->request->get($key, $this, $deep)) {
732+
if ($this !== $result = $this->request->get($key, $this)) {
740733
return $result;
741734
}
742735

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,41 +85,6 @@ public function testGetDoesNotUseDeepByDefault()
8585
$this->assertNull($bag->get('foo[bar]'));
8686
}
8787

88-
/**
89-
* @group legacy
90-
* @dataProvider getInvalidPaths
91-
* @expectedException \InvalidArgumentException
92-
*/
93-
public function testGetDeepWithInvalidPaths($path)
94-
{
95-
$bag = new ParameterBag(array('foo' => array('bar' => 'moo')));
96-
97-
$bag->get($path, null, true);
98-
}
99-
100-
public function getInvalidPaths()
101-
{
102-
return array(
103-
array('foo[['),
104-
array('foo[d'),
105-
array('foo[bar]]'),
106-
array('foo[bar]d'),
107-
);
108-
}
109-
110-
/**
111-
* @group legacy
112-
*/
113-
public function testGetDeep()
114-
{
115-
$bag = new ParameterBag(array('foo' => array('bar' => array('moo' => 'boo'))));
116-
117-
$this->assertEquals(array('moo' => 'boo'), $bag->get('foo[bar]', null, true));
118-
$this->assertEquals('boo', $bag->get('foo[bar][moo]', null, true));
119-
$this->assertEquals('default', $bag->get('foo[bar][foo]', 'default', true));
120-
$this->assertEquals('default', $bag->get('bar[moo][foo]', 'default', true));
121-
}
122-
12388
/**
12489
* @covers Symfony\Component\HttpFoundation\ParameterBag::set
12590
*/

src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function testFailurePathCanBeOverwritten()
145145
public function testFailurePathCanBeOverwrittenWithRequest()
146146
{
147147
$this->request->expects($this->once())
148-
->method('get')->with('_failure_path', null, false)
148+
->method('get')->with('_failure_path')
149149
->will($this->returnValue('/auth/login'));
150150

151151
$this->httpUtils->expects($this->once())
@@ -158,7 +158,7 @@ public function testFailurePathCanBeOverwrittenWithRequest()
158158
public function testFailurePathCanBeOverwrittenWithNestedAttributeInRequest()
159159
{
160160
$this->request->expects($this->once())
161-
->method('get')->with('_failure_path', null, false)
161+
->method('get')->with('_failure_path')
162162
->will($this->returnValue(array('value' => '/auth/login')));
163163

164164
$this->httpUtils->expects($this->once())
@@ -173,7 +173,7 @@ public function testFailurePathParameterCanBeOverwritten()
173173
$options = array('failure_path_parameter' => '_my_failure_path');
174174

175175
$this->request->expects($this->once())
176-
->method('get')->with('_my_failure_path', null, false)
176+
->method('get')->with('_my_failure_path')
177177
->will($this->returnValue('/auth/login'));
178178

179179
$this->httpUtils->expects($this->once())

0 commit comments

Comments
 (0)
0