bug #29183 [HttpKernel] Fix collecting uploaded files (ro0NL)

This PR was squashed before being merged into the 4.2-dev branch (closes #29183).

Discussion
----------

[HttpKernel] Fix collecting uploaded files

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29178
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Commits
-------

a439681bd4 [HttpKernel] Fix collecting uploaded files
This commit is contained in:
Nicolas Grekas 2018-11-13 17:04:24 +01:00
commit 3778585210
2 changed files with 15 additions and 9 deletions

View File

@ -143,7 +143,7 @@
<tr>
<th scope="col">File Name</th>
<th scope="col">MIME Type</th>
<th scope="col text-right">Size (bytes)</th>
<th scope="col" class="text-right">Size (bytes)</th>
</tr>
</thead>
<tbody>

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -58,15 +59,20 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
}
$requestFiles = array();
foreach ($request->files->all() as $files) {
foreach ($files as $fileName => $fileData) {
$requestFiles[] = array(
'name' => $fileData->getClientOriginalName(),
'mimetype' => $fileData->getMimeType(),
'size' => $fileData->getSize(),
);
$extractFiles = function (array $files) use (&$extractFiles, &$requestFiles) {
foreach ($files as $file) {
if ($file instanceof UploadedFile) {
$requestFiles[] = array(
'name' => $file->getClientOriginalName(),
'mimetype' => $file->getMimeType(),
'size' => $file->getSize(),
);
} elseif (\is_array($file)) {
$extractFiles($file);
}
}
}
};
$extractFiles($request->files->all());
$sessionMetadata = array();
$sessionAttributes = array();