Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6102f99

Browse filesBrowse files
committed
[HttpKernel] fixed serialization of the request data collector
1 parent 98c3fe7 commit 6102f99
Copy full SHA for 6102f99

File tree

Expand file treeCollapse file tree

2 files changed

+29
-21
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-21
lines changed

‎src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ public function collect(Request $request, Response $response, \Exception $except
4848
$responseHeaders['Set-Cookie'] = $cookies;
4949
}
5050

51+
// attributes are serialized and as they can be anything, they need to be converted to strings.
5152
$attributes = array();
5253
foreach ($request->attributes->all() as $key => $value) {
5354
if ('_route' === $key && is_object($value)) {
54-
$value = $value->getPath();
55+
$attributes[$key] = $this->varToString($value->getPath());
56+
} elseif ('_route_params' === $key) {
57+
// we need to keep route params as an array (see getRouteParams())
58+
foreach ($value as $k => $v) {
59+
$value[$k] = $this->varToString($v);
60+
}
61+
$attributes[$key] = $value;
62+
} else {
63+
$attributes[$key] = $this->varToString($value);
5564
}
56-
57-
$attributes[$key] = $value;
5865
}
5966

6067
$content = null;

‎src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php
+19-18Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,28 @@
2222

2323
class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
2424
{
25-
/**
26-
* @dataProvider provider
27-
*/
28-
public function testCollect(Request $request, Response $response)
25+
public function testCollect()
2926
{
3027
$c = new RequestDataCollector();
3128

32-
$c->collect($request, $response);
29+
$c->collect($this->createRequest(), $this->createResponse());
30+
31+
$attributes = $c->getRequestAttributes();
3332

3433
$this->assertSame('request', $c->getName());
3534
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getRequestHeaders());
3635
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer());
3736
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies());
38-
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestAttributes());
37+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
3938
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest());
4039
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
4140
$this->assertSame('html', $c->getFormat());
4241
$this->assertSame('foobar', $c->getRoute());
4342
$this->assertSame(array('name' => 'foo'), $c->getRouteParams());
4443
$this->assertSame(array(), $c->getSessionAttributes());
4544
$this->assertSame('en', $c->getLocale());
45+
$this->assertSame('Resource(stream)', $attributes->get('resource'));
46+
$this->assertSame('Object(stdClass)', $attributes->get('object'));
4647

4748
$this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag', $c->getResponseHeaders());
4849
$this->assertSame('OK', $c->getStatusText());
@@ -52,10 +53,8 @@ public function testCollect(Request $request, Response $response)
5253

5354
/**
5455
* Test various types of controller callables.
55-
*
56-
* @dataProvider provider
5756
*/
58-
public function testControllerInspection(Request $request, Response $response)
57+
public function testControllerInspection()
5958
{
6059
// make sure we always match the line number
6160
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
@@ -136,35 +135,37 @@ function () { return 'foo'; },
136135
);
137136

138137
$c = new RequestDataCollector();
139-
138+
$request = $this->createRequest();
139+
$response = $this->createResponse();
140140
foreach ($controllerTests as $controllerTest) {
141141
$this->injectController($c, $controllerTest[1], $request);
142142
$c->collect($request, $response);
143143
$this->assertSame($controllerTest[2], $c->getController(), sprintf('Testing: %s', $controllerTest[0]));
144144
}
145145
}
146146

147-
public function provider()
147+
protected function createRequest()
148148
{
149-
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
150-
return array(array(null, null));
151-
}
152-
153149
$request = Request::create('http://test.com/foo?bar=baz');
154150
$request->attributes->set('foo', 'bar');
155151
$request->attributes->set('_route', 'foobar');
156152
$request->attributes->set('_route_params', array('name' => 'foo'));
153+
$request->attributes->set('resource', fopen(__FILE__, 'r'));
154+
$request->attributes->set('object', new \stdClass());
155+
156+
return $request;
157+
}
157158

159+
protected function createResponse()
160+
{
158161
$response = new Response();
159162
$response->setStatusCode(200);
160163
$response->headers->set('Content-Type', 'application/json');
161164
$response->headers->setCookie(new Cookie('foo','bar',1,'/foo','localhost',true,true));
162165
$response->headers->setCookie(new Cookie('bar','foo',new \DateTime('@946684800')));
163166
$response->headers->setCookie(new Cookie('bazz','foo','2000-12-12'));
164167

165-
return array(
166-
array($request, $response)
167-
);
168+
return $response;
168169
}
169170

170171
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.