-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve extensibility by removing
@final
and making Stream's constr…
…uctor public (#203)
- Loading branch information
1 parent
53a0758
commit 1337944
Showing
9 changed files
with
16 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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']]); | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|