Skip to content

Commit

Permalink
Improve extensibility by removing @final and making Stream's constr…
Browse files Browse the repository at this point in the history
…uctor public (#203)
  • Loading branch information
nicolas-grekas authored Mar 31, 2023
1 parent 53a0758 commit 1337944
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 47 deletions.
20 changes: 0 additions & 20 deletions doc/final.md

This file was deleted.

2 changes: 0 additions & 2 deletions src/Factory/HttplugFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
/**
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
{
Expand Down
2 changes: 0 additions & 2 deletions src/Factory/Psr17Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
/**
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
{
Expand Down
2 changes: 0 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/**
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class Request implements RequestInterface
{
Expand Down
2 changes: 0 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class Response implements ResponseInterface
{
Expand Down
2 changes: 0 additions & 2 deletions src/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class ServerRequest implements ServerRequestInterface
{
Expand Down
29 changes: 16 additions & 13 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class Stream implements StreamInterface
{
Expand Down Expand Up @@ -51,8 +49,20 @@ class Stream implements StreamInterface
],
];

private function __construct()
/**
* @param resource $body
*/
public function __construct($body)
{
if (!\is_resource($body)) {
throw new \InvalidArgumentException('First argument to Stream::__construct() must be resource.');
}

$this->stream = $body;
$meta = \stream_get_meta_data($this->stream);
$this->seekable = $meta['seekable'] && 0 === \fseek($this->stream, 0, \SEEK_CUR);
$this->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
$this->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
}

/**
Expand All @@ -74,18 +84,11 @@ public static function create($body = ''): StreamInterface
$body = $resource;
}

if (\is_resource($body)) {
$new = new self();
$new->stream = $body;
$meta = \stream_get_meta_data($new->stream);
$new->seekable = $meta['seekable'] && 0 === \fseek($new->stream, 0, \SEEK_CUR);
$new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
$new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);

return $new;
if (!\is_resource($body)) {
throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
}

throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
return new self($body);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class UploadedFile implements UploadedFileInterface
{
Expand Down
2 changes: 0 additions & 2 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* @author Matthew Weier O'Phinney
* @author Tobias Nyholm <[email protected]>
* @author Martijn van der Ven <[email protected]>
*
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
*/
class Uri implements UriInterface
{
Expand Down

0 comments on commit 1337944

Please sign in to comment.