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

Commit

Permalink
revert: Reverts changes from #378
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weierophinney committed Nov 13, 2019
1 parent 6ef7906 commit 4d9905e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 18 deletions.
2 changes: 0 additions & 2 deletions docs/book/v2/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
7 changes: 1 addition & 6 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Diactoros;

use SplFileInfo;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;

Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions test/UploadedFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use RuntimeException;
use SplFileInfo;
use Zend\Diactoros\Stream;
use Zend\Diactoros\UploadedFile;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4d9905e

Please sign in to comment.