12
12
namespace Symfony \Component \HttpKernel \DataCollector ;
13
13
14
14
use Symfony \Component \HttpFoundation \ParameterBag ;
15
- use Symfony \Component \HttpFoundation \HeaderBag ;
16
15
use Symfony \Component \HttpFoundation \Request ;
17
16
use Symfony \Component \HttpFoundation \Response ;
18
- use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
19
17
use Symfony \Component \HttpKernel \Event \FilterResponseEvent ;
20
18
use Symfony \Component \HttpKernel \KernelEvents ;
21
19
use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
@@ -54,14 +52,10 @@ public function collect(Request $request, Response $response, \Exception $except
54
52
$ attributes = array ();
55
53
$ route = '' ;
56
54
foreach ($ request ->attributes ->all () as $ key => $ value ) {
57
- if ('_route ' === $ key && is_object ($ value )) {
58
- $ attributes [$ key ] = $ this ->cloneVar ($ value ->getPath ());
59
- } else {
60
- $ attributes [$ key ] = $ this ->cloneVar ($ value );
61
- }
62
-
63
55
if ('_route ' === $ key ) {
64
- $ route = is_object ($ value ) ? $ value ->getPath () : $ value ;
56
+ $ attributes [$ key ] = $ route = is_object ($ value ) ? $ value ->getPath () : $ value ;
57
+ } else {
58
+ $ attributes [$ key ] = $ value ;
65
59
}
66
60
}
67
61
@@ -97,8 +91,8 @@ public function collect(Request $request, Response $response, \Exception $except
97
91
'content_type ' => $ response ->headers ->get ('Content-Type ' , 'text/html ' ),
98
92
'status_text ' => isset (Response::$ statusTexts [$ statusCode ]) ? Response::$ statusTexts [$ statusCode ] : '' ,
99
93
'status_code ' => $ statusCode ,
100
- 'request_query ' => array_map ( array ( $ this , ' cloneVar ' ), $ request ->query ->all () ),
101
- 'request_request ' => array_map ( array ( $ this , ' cloneVar ' ), $ request ->request ->all () ),
94
+ 'request_query ' => $ request ->query ->all (),
95
+ 'request_request ' => $ request ->request ->all (),
102
96
'request_headers ' => $ request ->headers ->all (),
103
97
'request_server ' => $ request ->server ->all (),
104
98
'request_cookies ' => $ request ->cookies ->all (),
@@ -125,6 +119,18 @@ public function collect(Request $request, Response $response, \Exception $except
125
119
$ this ->data ['request_request ' ]['_password ' ] = '****** ' ;
126
120
}
127
121
122
+ foreach ($ this ->data as $ key => $ value ) {
123
+ if (!is_array ($ value )) {
124
+ continue ;
125
+ }
126
+ if ('request_headers ' === $ key || 'response_headers ' === $ key ) {
127
+ $ value = array_map (function ($ v ) { return isset ($ v [1 ]) ? $ v : $ v [0 ]; }, $ value );
128
+ }
129
+ if ('request_server ' !== $ key && 'request_attributes ' !== $ key && 'request_cookies ' !== $ key ) {
130
+ $ this ->data [$ key ] = array_map (array ($ this , 'cloneVar ' ), $ value );
131
+ }
132
+ }
133
+
128
134
if (isset ($ this ->controllers [$ request ])) {
129
135
$ this ->data ['controller ' ] = $ this ->parseController ($ this ->controllers [$ request ]);
130
136
unset($ this ->controllers [$ request ]);
@@ -170,27 +176,27 @@ public function getRequestQuery()
170
176
171
177
public function getRequestHeaders ()
172
178
{
173
- return new HeaderBag ($ this ->data ['request_headers ' ]);
179
+ return new ParameterBag ($ this ->data ['request_headers ' ]);
174
180
}
175
181
176
- public function getRequestServer ()
182
+ public function getRequestServer ($ raw = false )
177
183
{
178
- return new ParameterBag ($ this ->data ['request_server ' ]);
184
+ return new ParameterBag ($ raw ? $ this ->data ['request_server ' ] : array_map ( array ( $ this , ' cloneVar ' ), $ this -> data [ ' request_server ' ]) );
179
185
}
180
186
181
- public function getRequestCookies ()
187
+ public function getRequestCookies ($ raw = false )
182
188
{
183
- return new ParameterBag ($ this ->data ['request_cookies ' ]);
189
+ return new ParameterBag ($ raw ? $ this ->data ['request_cookies ' ] : array_map ( array ( $ this , ' cloneVar ' ), $ this -> data [ ' request_cookies ' ]) );
184
190
}
185
191
186
- public function getRequestAttributes ()
192
+ public function getRequestAttributes ($ raw = false )
187
193
{
188
- return new ParameterBag ($ this ->data ['request_attributes ' ]);
194
+ return new ParameterBag ($ raw ? $ this ->data ['request_attributes ' ] : array_map ( array ( $ this , ' cloneVar ' ), $ this -> data [ ' request_attributes ' ]) );
189
195
}
190
196
191
197
public function getResponseHeaders ()
192
198
{
193
- return new ResponseHeaderBag ($ this ->data ['response_headers ' ]);
199
+ return new ParameterBag ($ this ->data ['response_headers ' ]);
194
200
}
195
201
196
202
public function getSessionMetadata ()
@@ -264,7 +270,11 @@ public function getIdentifier()
264
270
*/
265
271
public function getRouteParams ()
266
272
{
267
- return isset ($ this ->data ['request_attributes ' ]['_route_params ' ]) ? $ this ->data ['request_attributes ' ]['_route_params ' ] : $ this ->cloneVar (array ());
273
+ if (!isset ($ this ->data ['request_attributes ' ]['_route_params ' ])) {
274
+ return array ();
275
+ }
276
+
277
+ return array_map (array ($ this , 'cloneVar ' ), $ this ->data ['request_attributes ' ]['_route_params ' ]);
268
278
}
269
279
270
280
/**
0 commit comments