Skip to content

Commit d922786

Browse files
[HttpKernel] Fix exception when serializing request attributes
1 parent 81ba5a1 commit d922786

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

DataCollector/RequestDataCollector.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function collect(Request $request, Response $response, \Exception $except
127127
if ('request_headers' === $key || 'response_headers' === $key) {
128128
$value = array_map(function ($v) { return isset($v[1]) ? $v : $v[0]; }, $value);
129129
}
130-
if ('request_server' !== $key && 'request_attributes' !== $key && 'request_cookies' !== $key) {
130+
if ('request_server' !== $key && 'request_cookies' !== $key) {
131131
$this->data[$key] = array_map(array($this, 'cloneVar'), $value);
132132
}
133133
}
@@ -190,9 +190,9 @@ public function getRequestCookies($raw = false)
190190
return new ParameterBag($raw ? $this->data['request_cookies'] : array_map(array($this, 'cloneVar'), $this->data['request_cookies']));
191191
}
192192

193-
public function getRequestAttributes($raw = false)
193+
public function getRequestAttributes()
194194
{
195-
return new ParameterBag($raw ? $this->data['request_attributes'] : array_map(array($this, 'cloneVar'), $this->data['request_attributes']));
195+
return new ParameterBag($this->data['request_attributes']);
196196
}
197197

198198
public function getResponseHeaders()
@@ -271,7 +271,17 @@ public function getIdentifier()
271271
*/
272272
public function getRouteParams()
273273
{
274-
return isset($this->data['request_attributes']['_route_params']) ? array_map(array($this, 'cloneVar'), $this->data['request_attributes']['_route_params']) : array();
274+
if (!isset($this->data['request_attributes']['_route_params'])) {
275+
return array();
276+
}
277+
278+
$data = $this->data['request_attributes']['_route_params'];
279+
$params = array();
280+
foreach ($data->getRawData()[1] as $k => $v) {
281+
$params[$k] = $data->seek($k);
282+
}
283+
284+
return $params;
275285
}
276286

277287
/**

Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testCollect()
4747
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
4848
$this->assertSame('html', $c->getFormat());
4949
$this->assertEquals('foobar', $c->getRoute());
50-
$this->assertEquals(array('name' => $cloner->cloneVar('foo')), $c->getRouteParams());
50+
$this->assertEquals(array('name' => $cloner->cloneVar(array('name' => 'foo'))->seek('name')), $c->getRouteParams());
5151
$this->assertSame(array(), $c->getSessionAttributes());
5252
$this->assertSame('en', $c->getLocale());
5353
$this->assertEquals($cloner->cloneVar($request->attributes->get('resource')), $attributes->get('resource'));

0 commit comments

Comments
 (0)