-
-
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.
* Remove final keyword * Added changelog * Added docs to final * Update doc/final.md Co-authored-by: Martijn van der Ven <[email protected]> * Added link to decorator pattern Co-authored-by: Martijn van der Ven <[email protected]>
- Loading branch information
Showing
10 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Final classes | ||
|
||
The `final` keyword was removed in version 1.4.0. It was replaced by `@final` annotation. | ||
This was done due popular demand, not because it is a good technical reason to | ||
extend the classes. | ||
|
||
This document will show the correct way to work with PSR-7 classes. The "correct way" | ||
refers to best practices and good software design. I strongly believe that one should | ||
be aware of how a problem *should* be solved, however, it is not needed to always | ||
implement that solution. | ||
|
||
## Extending classes | ||
|
||
You should never extend the classes, you should rather use composition or implement | ||
the interface yourself. Please refer to the [decorator pattern](https://refactoring.guru/design-patterns/decorator). | ||
|
||
## Mocking classes | ||
|
||
The PSR-7 classes are all value objects and they can be used without mocking. If | ||
one really needs to create a special scenario, one can mock the interface instead. |
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 |
---|---|---|
|
@@ -11,8 +11,10 @@ | |
/** | ||
* @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 | ||
*/ | ||
final class HttplugFactory implements MessageFactory, StreamFactory, UriFactory | ||
class HttplugFactory implements MessageFactory, StreamFactory, UriFactory | ||
{ | ||
public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1') | ||
{ | ||
|
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,10 @@ | |
/** | ||
* @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 | ||
*/ | ||
final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface | ||
class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface | ||
{ | ||
public function createRequest(string $method, $uri): 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 |
---|---|---|
|
@@ -9,8 +9,10 @@ | |
/** | ||
* @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 | ||
*/ | ||
final class Request implements RequestInterface | ||
class Request implements RequestInterface | ||
{ | ||
use MessageTrait; | ||
use RequestTrait; | ||
|
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,10 @@ | |
* @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 | ||
*/ | ||
final class Response implements ResponseInterface | ||
class Response implements ResponseInterface | ||
{ | ||
use MessageTrait; | ||
|
||
|
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,10 @@ | |
* @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 | ||
*/ | ||
final class ServerRequest implements ServerRequestInterface | ||
class ServerRequest implements ServerRequestInterface | ||
{ | ||
use MessageTrait; | ||
use RequestTrait; | ||
|
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,10 @@ | |
* @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 | ||
*/ | ||
final class Stream implements StreamInterface | ||
class Stream implements StreamInterface | ||
{ | ||
/** @var resource|null A resource reference */ | ||
private $stream; | ||
|
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,10 @@ | |
* @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 | ||
*/ | ||
final class UploadedFile implements UploadedFileInterface | ||
class UploadedFile implements UploadedFileInterface | ||
{ | ||
/** @var array */ | ||
private const ERRORS = [ | ||
|
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,10 @@ | |
* @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 | ||
*/ | ||
final class Uri implements UriInterface | ||
class Uri implements UriInterface | ||
{ | ||
private const SCHEMES = ['http' => 80, 'https' => 443]; | ||
|
||
|