From 346854bdc5a54d3bd4701ea8fbebdbe66063c651 Mon Sep 17 00:00:00 2001 From: hrayr Date: Fri, 14 Aug 2020 12:31:24 +0400 Subject: [PATCH] Add method returning client provided file path UploadedFile class has a property containing temporary path of the uploaded file, which is inaccessible outside of the class. But there is a need of accessing this property outside of the class, when for example you must upload the uploaded file directly to the cloud(e.g. Amazon S3 bucket) without saving it to your local file system. So a getter method is created returning the value of this property. --- src/UploadedFile.php | 12 ++++++++++++ tests/UploadedFileTest.php | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/UploadedFile.php b/src/UploadedFile.php index 5c3f438..0ddfed3 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -208,6 +208,18 @@ public function getSize(): ?int { return $this->size; } + + /** + * Returns the client-provided full path to the file + * + * @internal This method is not part of the PSR-7 standard + * + * @return string + */ + public function getFilePath(): string + { + return $this->file; + } /** * Create a normalized tree of UploadedFile instances from the Environment. diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index 82d3471..adeefaa 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -153,6 +153,7 @@ public function testConstructor() $this->assertEquals($attr['type'], $uploadedFile->getClientMediaType()); $this->assertEquals($attr['size'], $uploadedFile->getSize()); $this->assertEquals($attr['error'], $uploadedFile->getError()); + $this->assertEquals($attr['tmp_name'], $uploadedFile->getFilePath()); return $uploadedFile; } @@ -183,6 +184,7 @@ public function testConstructorSapi() $this->assertEquals($attr['type'], $uploadedFile->getClientMediaType()); $this->assertEquals($attr['size'], $uploadedFile->getSize()); $this->assertEquals($attr['error'], $uploadedFile->getError()); + $this->assertEquals($attr['tmp_name'], $uploadedFile->getFilePath()); return $uploadedFile; } @@ -409,6 +411,7 @@ private function runFileUploadWithTempStreamTest(callable $streamFactory, callab $this->assertSame($error, $file->getError()); $this->assertSame($clientFilename, $file->getClientFilename()); $this->assertSame($clientMediaType, $file->getClientMediaType()); + $this->assertSame($stream->getMetadata('uri'), $file->getFilePath()); } /**