Skip to content

Commit

Permalink
Add method returning client provided file path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hhovakimyan committed Aug 14, 2020
1 parent 5b19133 commit 346854b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tests/UploadedFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 346854b

Please sign in to comment.