From 36f194d6c75b647ffb3618bd45e0d6d7e5af4a2b Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 13 Nov 2019 12:00:48 -0600 Subject: [PATCH] revert: Reverts changes from #378 Post-release, users discovered problems with `UploadedFile` extending `SplFileInfo`, particularly when a stream path is used to create the instance. Additionally, there are some differences with how `UploadedFileInterface` and `SplFileInfo` each define the return type for `getSize()`; the former allows nullification, while the latter does not, but allows raising an exception (something explicitly disallowed in PSR-7). This patch reverts the code and documentation changes associated with the patch. --- docs/book/v2/api.md | 2 -- src/UploadedFile.php | 7 +------ test/UploadedFileTest.php | 10 ---------- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/docs/book/v2/api.md b/docs/book/v2/api.md index 7dd3b2f6..a37cfb46 100644 --- a/docs/book/v2/api.md +++ b/docs/book/v2/api.md @@ -194,6 +194,4 @@ 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`. diff --git a/src/UploadedFile.php b/src/UploadedFile.php index a28b7af5..2f4d87f1 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -9,7 +9,6 @@ namespace Zend\Diactoros; -use SplFileInfo; use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UploadedFileInterface; @@ -36,7 +35,7 @@ use const UPLOAD_ERR_OK; use const UPLOAD_ERR_PARTIAL; -class UploadedFile extends SplFileInfo implements UploadedFileInterface +class UploadedFile implements UploadedFileInterface { const ERROR_MESSAGES = [ UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', @@ -103,13 +102,9 @@ 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) { diff --git a/test/UploadedFileTest.php b/test/UploadedFileTest.php index 80e90eb8..35ab5edb 100644 --- a/test/UploadedFileTest.php +++ b/test/UploadedFileTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use ReflectionProperty; use RuntimeException; -use SplFileInfo; use Zend\Diactoros\Stream; use Zend\Diactoros\UploadedFile; @@ -326,13 +325,4 @@ 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); - } }