diff --git a/Bridges/HttpKernel.php b/Bridges/HttpKernel.php index fdfaee0..40c7c23 100644 --- a/Bridges/HttpKernel.php +++ b/Bridges/HttpKernel.php @@ -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 @@ -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 *