From bfe7a22944fe876ba3bc7648301c3c184f5be229 Mon Sep 17 00:00:00 2001 From: "Matthew J. Sahagian" Date: Fri, 8 Nov 2019 11:36:38 -0800 Subject: [PATCH 1/4] Making UploadedFile extend SplFileInfo --- src/UploadedFile.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/UploadedFile.php b/src/UploadedFile.php index 2f4d87f1..a28b7af5 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -9,6 +9,7 @@ namespace Zend\Diactoros; +use SplFileInfo; use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UploadedFileInterface; @@ -35,7 +36,7 @@ use const UPLOAD_ERR_OK; use const UPLOAD_ERR_PARTIAL; -class UploadedFile implements UploadedFileInterface +class UploadedFile extends SplFileInfo implements UploadedFileInterface { const ERROR_MESSAGES = [ UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', @@ -102,9 +103,13 @@ public function __construct( if ($errorStatus === UPLOAD_ERR_OK) { if (is_string($streamOrFile)) { $this->file = $streamOrFile; + + parent::__construct($this->file); } if (is_resource($streamOrFile)) { $this->stream = new Stream($streamOrFile); + + parent::__construct($this->stream->getMetaData('uri')); } if (! $this->file && ! $this->stream) { From d4dec997b473e880f6d43b11dc8445db0217cac1 Mon Sep 17 00:00:00 2001 From: "Matthew J. Sahagian" Date: Fri, 8 Nov 2019 11:51:37 -0800 Subject: [PATCH 2/4] Changelog + doc changes --- CHANGELOG.md | 26 ++++++++++++++++++++++++-- docs/book/v2/api.md | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d9a5f5a..86654312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.2.0 - TBD +## 2.2.1 - TBD ### Added @@ -24,6 +24,28 @@ All notable changes to this project will be documented in this file, in reverse - Nothing. +## 2.2.0 - 2019-11-08 + +### Added + +- [#377](https://github.com/zendframework/zend-diactoros/issues/377) enables UploadedFile to stand in and be used as an SplFileInfo object. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 2.1.6 - TBD ### Added @@ -641,7 +663,7 @@ All notable changes to this project will be documented in this file, in reverse - [#293](https://github.com/zendframework/zend-diactoros/pull/293) updates `Uri::getHost()` to cast the value via `strtolower()` before returning it. - While this represents a change, it is fixing a bug in our implementation: + While this represents a change, it is fixing a bug in our implementation: the PSR-7 specification for the method, which follows IETF RFC 3986 section 3.2.2, requires that the host name be normalized to lowercase. diff --git a/docs/book/v2/api.md b/docs/book/v2/api.md index a37cfb46..7dd3b2f6 100644 --- a/docs/book/v2/api.md +++ b/docs/book/v2/api.md @@ -194,4 +194,6 @@ In most cases, you will not interact with the Stream object directly. and provides abstraction around a single uploaded file, including behavior for interacting with it as a stream or moving it to a filesystem location. +Additionally, it extends PHP's build in `SplFileInfo` object in order to provide a compatible interface wherever such an object is needed. + In most cases, you will only use the methods defined in the `UploadedFileInterface`. From f38c319dd284b18fd47f9b83affd41402fba97b2 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 12 Nov 2019 11:18:02 -0600 Subject: [PATCH 3/4] qa: adds tests for #378 --- test/UploadedFileTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/UploadedFileTest.php b/test/UploadedFileTest.php index 35ab5edb..80e90eb8 100644 --- a/test/UploadedFileTest.php +++ b/test/UploadedFileTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use ReflectionProperty; use RuntimeException; +use SplFileInfo; use Zend\Diactoros\Stream; use Zend\Diactoros\UploadedFile; @@ -325,4 +326,13 @@ public function testMoveToRaisesExceptionWithAppropriateMessageWhenUploadErrorDe $this->expectExceptionMessage($message); $uploadedFile->moveTo('/tmp/foo'); } + + /** + * @see https://github.com/zendframework/zend-diactoros/pull/378 + */ + public function testExtendsSplFileInfo() + { + $uploaded = new UploadedFile(fopen('php://temp', 'wb+'), 0, UPLOAD_ERR_OK); + $this->assertInstanceOf(SplFileInfo::class, $uploaded); + } } From b6d4ed1d97083bb4d3240a65272bf38748bd6d45 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 12 Nov 2019 11:21:38 -0600 Subject: [PATCH 4/4] docs: adds CHANGELOG entry for #378 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86654312..379616ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse ### Changed -- Nothing. +- [#378](https://github.com/zendframework/zend-diactoros/pull/378) updates the `UploadedFile` class to extend `SplFileInfo`, allowing developers to make use of those features in their applications. ### Deprecated