Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 4d9905e

Browse files
committed
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.
1 parent 6ef7906 commit 4d9905e

File tree

3 files changed

+1
-18
lines changed

3 files changed

+1
-18
lines changed

docs/book/v2/api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,4 @@ In most cases, you will not interact with the Stream object directly.
194194
and provides abstraction around a single uploaded file, including behavior for interacting with it
195195
as a stream or moving it to a filesystem location.
196196

197-
Additionally, it extends PHP's build in `SplFileInfo` object in order to provide a compatible interface wherever such an object is needed.
198-
199197
In most cases, you will only use the methods defined in the `UploadedFileInterface`.

src/UploadedFile.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Zend\Diactoros;
1111

12-
use SplFileInfo;
1312
use Psr\Http\Message\StreamInterface;
1413
use Psr\Http\Message\UploadedFileInterface;
1514

@@ -36,7 +35,7 @@
3635
use const UPLOAD_ERR_OK;
3736
use const UPLOAD_ERR_PARTIAL;
3837

39-
class UploadedFile extends SplFileInfo implements UploadedFileInterface
38+
class UploadedFile implements UploadedFileInterface
4039
{
4140
const ERROR_MESSAGES = [
4241
UPLOAD_ERR_OK => 'There is no error, the file uploaded with success',
@@ -103,13 +102,9 @@ public function __construct(
103102
if ($errorStatus === UPLOAD_ERR_OK) {
104103
if (is_string($streamOrFile)) {
105104
$this->file = $streamOrFile;
106-
107-
parent::__construct($this->file);
108105
}
109106
if (is_resource($streamOrFile)) {
110107
$this->stream = new Stream($streamOrFile);
111-
112-
parent::__construct($this->stream->getMetaData('uri'));
113108
}
114109

115110
if (! $this->file && ! $this->stream) {

test/UploadedFileTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PHPUnit\Framework\TestCase;
1414
use ReflectionProperty;
1515
use RuntimeException;
16-
use SplFileInfo;
1716
use Zend\Diactoros\Stream;
1817
use Zend\Diactoros\UploadedFile;
1918

@@ -326,13 +325,4 @@ public function testMoveToRaisesExceptionWithAppropriateMessageWhenUploadErrorDe
326325
$this->expectExceptionMessage($message);
327326
$uploadedFile->moveTo('/tmp/foo');
328327
}
329-
330-
/**
331-
* @see https://github.com/zendframework/zend-diactoros/pull/378
332-
*/
333-
public function testExtendsSplFileInfo()
334-
{
335-
$uploaded = new UploadedFile(fopen('php://temp', 'wb+'), 0, UPLOAD_ERR_OK);
336-
$this->assertInstanceOf(SplFileInfo::class, $uploaded);
337-
}
338328
}

0 commit comments

Comments
 (0)