Skip to content

Commit

Permalink
Fix cyclic reference preventing gc (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnna authored and andig committed Mar 24, 2019
1 parent e974a26 commit 057f02e
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions Bridges/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,7 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
/** @var \React\Http\Io\UploadedFile $file */
$uploadedFiles = $psrRequest->getUploadedFiles();

$mapFiles = function (&$files) use (&$mapFiles) {
foreach ($files as &$file) {
if (is_array($file)) {
$mapFiles($file);
} elseif ($file instanceof UploadedFileInterface) {
$tmpname = tempnam(sys_get_temp_dir(), 'upload');
$this->tempFiles[] = $tmpname;

if (UPLOAD_ERR_NO_FILE == $file->getError()) {
$file = [
'error' => $file->getError(),
'name' => $file->getClientFilename(),
'size' => $file->getSize(),
'tmp_name' => $tmpname,
'type' => $file->getClientMediaType()
];
} else {
if (UPLOAD_ERR_OK == $file->getError()) {
file_put_contents($tmpname, (string)$file->getStream());
}
$file = new SymfonyFile(
$tmpname,
$file->getClientFilename(),
$file->getClientMediaType(),
$file->getSize(),
$file->getError(),
true
);
}
}
}
};
$mapFiles($uploadedFiles);
$this->mapFiles($uploadedFiles);

// @todo check howto handle additional headers
// @todo check howto support other HTTP methods with bodies
Expand All @@ -194,6 +162,40 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
return $syRequest;
}

private function mapFiles(&$files)
{
foreach ($files as &$file) {
if (is_array($file)) {
$this->mapFiles($file);
} elseif ($file instanceof UploadedFileInterface) {
$tmpname = tempnam(sys_get_temp_dir(), 'upload');
$this->tempFiles[] = $tmpname;

if (UPLOAD_ERR_NO_FILE == $file->getError()) {
$file = [
'error' => $file->getError(),
'name' => $file->getClientFilename(),
'size' => $file->getSize(),
'tmp_name' => $tmpname,
'type' => $file->getClientMediaType(),
];
} else {
if (UPLOAD_ERR_OK == $file->getError()) {
file_put_contents($tmpname, (string)$file->getStream());
}
$file = new SymfonyFile(
$tmpname,
$file->getClientFilename(),
$file->getClientMediaType(),
$file->getSize(),
$file->getError(),
true
);
}
}
}
}

/**
* Convert Symfony\Component\HttpFoundation\Response to React\Http\Response
*
Expand Down

0 comments on commit 057f02e

Please sign in to comment.