Skip to content

Commit 4c1e8bd

Browse files
committed
bug #29285 [HttpKernel][WebProfilerBundle] Getting the cached client mime type instead of guessing it again (yceruto)
This PR was squashed before being merged into the 4.2-dev branch (closes #29285). Discussion ---------- [HttpKernel][WebProfilerBundle] Getting the cached client mime type instead of guessing it again | Q | A | ------------- | --- | Branch? | master (4.2) | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29284 | License | MIT | Doc PR | - The 1st commit fixes the bug based on the current implementation. But I'd like to improve this new feature a little bit with the 2nd commit: * <del>Renaming "Uploaded files" title by "FILES Parameters" and</del> (sub-section of POST parameters) changing the table using key/value structure (being consistent with other sections). * The above allow us also to show nested paramaters. (It is useful to know where this file(s) comes from) * And show all info about the `UploadedFile` object. (It might be useful too) ![files-parameters](https://user-images.githubusercontent.com/2028198/48918478-d3a3e100-ee5a-11e8-8ef7-a50ae4ee1550.png) Commits ------- 38692a6 [HttpKernel][WebProfilerBundle] Getting the cached client mime type instead of guessing it again
2 parents d9f87b6 + 38692a6 commit 4c1e8bd

File tree

2 files changed

+4
-38
lines changed

2 files changed

+4
-38
lines changed

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

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

134-
<h3>Uploaded files</h3>
134+
<h4>Uploaded Files</h4>
135135

136136
{% if collector.requestfiles is empty %}
137137
<div class="empty">
138138
<p>No files were uploaded</p>
139139
</div>
140140
{% 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" class="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>
141+
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestfiles, maxDepth: 1 }, with_context = false) }}
159142
{% endif %}
160143

161144
<h3>Request Attributes</h3>

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\HttpFoundation\Cookie;
16-
use Symfony\Component\HttpFoundation\File\UploadedFile;
1716
use Symfony\Component\HttpFoundation\ParameterBag;
1817
use Symfony\Component\HttpFoundation\Request;
1918
use Symfony\Component\HttpFoundation\Response;
@@ -58,22 +57,6 @@ public function collect(Request $request, Response $response, \Exception $except
5857
$content = false;
5958
}
6059

61-
$requestFiles = array();
62-
$extractFiles = function (array $files) use (&$extractFiles, &$requestFiles) {
63-
foreach ($files as $file) {
64-
if ($file instanceof UploadedFile) {
65-
$requestFiles[] = array(
66-
'name' => $file->getClientOriginalName(),
67-
'mimetype' => $file->getMimeType(),
68-
'size' => $file->getSize(),
69-
);
70-
} elseif (\is_array($file)) {
71-
$extractFiles($file);
72-
}
73-
}
74-
};
75-
$extractFiles($request->files->all());
76-
7760
$sessionMetadata = array();
7861
$sessionAttributes = array();
7962
$session = null;
@@ -112,7 +95,7 @@ public function collect(Request $request, Response $response, \Exception $except
11295
'status_code' => $statusCode,
11396
'request_query' => $request->query->all(),
11497
'request_request' => $request->request->all(),
115-
'request_files' => $requestFiles,
98+
'request_files' => $request->files->all(),
11699
'request_headers' => $request->headers->all(),
117100
'request_server' => $request->server->all(),
118101
'request_cookies' => $request->cookies->all(),
@@ -216,7 +199,7 @@ public function getRequestQuery()
216199

217200
public function getRequestFiles()
218201
{
219-
return $this->data['request_files']->getValue(true);
202+
return new ParameterBag($this->data['request_files']->getValue());
220203
}
221204

222205
public function getRequestHeaders()

0 commit comments

Comments
 (0)