Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b9c142

Browse files
committed
feature #26946 [WebProfilerBundle] Display uploaded files in the profiler (javiereguiluz)
This PR was squashed before being merged into the 4.2-dev branch (closes #26946). Discussion ---------- [WebProfilerBundle] Display uploaded files in the profiler | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26926 | License | MIT | Doc PR | - ![profiler_files](https://user-images.githubusercontent.com/73419/38807087-ac1e9bac-417b-11e8-99e0-317b437c986e.png) Note: I wanted to use the VarDumper to display the table information (as we do in the rest of tables) but I had lots of problems and I just wanted to create a proof of concept for the feature to see if we like it. Commits ------- 3f6f75b [WebProfilerBundle] Display uploaded files in the profiler
2 parents 21a3439 + 3f6f75b commit 2b9c142

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,33 @@
131131
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest, maxDepth: 1 }, with_context = false) }}
132132
{% endif %}
133133

134+
<h3>Uploaded files</h3>
135+
136+
{% if collector.requestfiles is empty %}
137+
<div class="empty">
138+
<p>No files were uploaded</p>
139+
</div>
140+
{% else %}
141+
<table>
142+
<thead>
143+
<tr>
144+
<th scope="col">File Name</th>
145+
<th scope="col">MIME Type</th>
146+
<th scope="col text-right">Size (bytes)</th>
147+
</tr>
148+
</thead>
149+
<tbody>
150+
{% for file in collector.requestfiles %}
151+
<tr>
152+
<td>{{ file.name }}</td>
153+
<td>{{ file.mimetype }}</td>
154+
<td class="text-right">{{ file.size|number_format }}</td>
155+
</tr>
156+
{% endfor %}
157+
</tbody>
158+
</table>
159+
{% endif %}
160+
134161
<h3>Request Attributes</h3>
135162

136163
{% if collector.requestattributes.all is empty %}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function collect(Request $request, Response $response, \Exception $except
5757
$content = false;
5858
}
5959

60+
$requestFiles = array();
61+
foreach ($request->files->all() as $files) {
62+
foreach ($files as $fileName => $fileData) {
63+
$requestFiles[] = array(
64+
'name' => $fileData->getClientOriginalName(),
65+
'mimetype' => $fileData->getMimeType(),
66+
'size' => $fileData->getSize(),
67+
);
68+
}
69+
}
70+
6071
$sessionMetadata = array();
6172
$sessionAttributes = array();
6273
$session = null;
@@ -95,6 +106,7 @@ public function collect(Request $request, Response $response, \Exception $except
95106
'status_code' => $statusCode,
96107
'request_query' => $request->query->all(),
97108
'request_request' => $request->request->all(),
109+
'request_files' => $requestFiles,
98110
'request_headers' => $request->headers->all(),
99111
'request_server' => $request->server->all(),
100112
'request_cookies' => $request->cookies->all(),
@@ -195,6 +207,11 @@ public function getRequestQuery()
195207
return new ParameterBag($this->data['request_query']->getValue());
196208
}
197209

210+
public function getRequestFiles()
211+
{
212+
return $this->data['request_files']->getValue(true);
213+
}
214+
198215
public function getRequestHeaders()
199216
{
200217
return new ParameterBag($this->data['request_headers']->getValue());

0 commit comments

Comments
 (0)