-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow usage with PSR-7 v2 #136
Conversation
3ee086f
to
f93a471
Compare
I do not believe this description is accurate. A deriving class may leave out parameter types of a parent class (“widen the type”), because everything that may be passed to the parent class may still be passed to the deriving class: https://3v4l.org/gfWBN However adding parameter types may break consumers that rely on passing an invalid type. However to my understanding, Diactoros already included checks to validate the type. So, I believe this is safe for a minor, unless I'm missing something? |
Many tests become redundant with proper types present. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
f93a471
to
cd4cf29
Compare
You were right about the contravariance versus covariance bit; I had that part wrong in the description and have since corrected it. The problem is actually with the return type hints: when we were defining return type hints in this implementation, we missed a few cases that later became |
I wonder if we should pin php-http integration tests to specific versions anyway. Since they can change upstream, it might lead to failing checks in PRs which are unrelated to those changes. Having renovate bumping these commits could help, no? |
cd4cf29
to
2b6ece7
Compare
That would only affect latest branch. |
More than enough for PRs.
Having scheduled build for that where we explictly use |
Both dependencies got releases. |
…ests - Updates to version 1.0.2 of the PSR-17 interfaces, which allow usage with PSR-7 v2 - Updates to version 1.3.0 of the psr7-integration-tests, which allow usage with PSR-7 1.1 and 2.0. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Due to updating to use PSR-7 v2, we can remove a number of conditionals that did type-checking, and also update constructors to use union types to fully type the API exposed. Doing so removes the need for some unit tests, as type errors will now be guaranteed by the runtime. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
- Updates the ref for the PSR-7 integration tests with a version known to work. - Fixes the signature of `CallbackStream::seek` to add the `void` return declaration. - Applies CS rules. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
- Update to stable http-factory with support for PSR-7 v2. - Updates to add settings that will be required with Psalm 6. - Removes some unnecessary type checks, as parameter type declarations are now present. - Updates tests to remove assertions about types when they are known. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Unused import statements Signed-off-by: Matthew Weier O'Phinney <[email protected]>
5fe22f5
to
22eca5b
Compare
I've now created the 3.0.x branch, and updated this patch to be against that branch. Additionally, both psr/http-factory and php-http/psr7-integration-tests have released stable versions that support PSR-7 1.1 and 2.0, allowing me to rebase my patch to reference the stable branches. Ready for final review and release! Once done, I'll turn my efforts to laminas/laminas-stratigility, and then the various Mezzio components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
We still need to test _string_ versions that resolve to unsupported protocol versions. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Per @Xerkus Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Per @Xerkus Signed-off-by: Matthew Weier O'Phinney <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Thanks @weierophinney!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laminas-diactoros/src/RequestTrait.php
Line 156 in 22eca5b
public function withRequestTarget($requestTarget): RequestInterface |
Missing parent type declaration.
Some tangentially related comments:
laminas-diactoros/src/UploadedFile.php
Lines 60 to 62 in 22eca5b
public function __construct( | |
$streamOrFile, | |
private int $size, |
Interface defines size as nullable. This should probably be changed to nullable too. If so this will need to be backported to 2.x
laminas-diactoros/src/MessageTrait.php
Line 353 in 22eca5b
private function validateProtocolVersion($version): void |
MessageTrait::validateProtocolVersion()
could have argument type defined and is_string check dropped to match withProtocolVersion()
.
laminas-diactoros/src/ServerRequest.php
Line 176 in 22eca5b
public function getAttribute(string $attribute, $default = null) |
This uses parameter name $attribute
and interface uses $name
. Should be changed for consistency. Same for withAttribute()
laminas-diactoros/src/StreamFactory.php
Line 31 in 22eca5b
public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface |
Interface uses
$filename
Thanks - updating that now. |
While the size can be nullable, we're saying in this particular implementation that it must be an integer. Since this narrows what we return from |
…Target()` should be string! Signed-off-by: Matthew Weier O'Phinney <[email protected]>
…rait::validateProtocolVersion` We know it's a string internally, so we can mark it one here, and remove a redundant conditional. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
This somewhat conflicts with the argument of UriFactory as using null will lead to type error laminas-diactoros/src/UploadedFileFactory.php Lines 18 to 30 in 22eca5b
|
I think these should be done with the 2.x series, and then merged up. |
Alright, that argument I can get behind. I'll make it nullable, but not have a default value. |
Since the `UploadedFileFactoryInterface` allows nullable size, not allowing it here could lead to an error condition. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Will you make PR against 2.x or should I? |
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@Xerkus — I've pushed changes for each of the following issues you flagged:
I've been thinking about the parameter name changes, and it DOES NOT make sense to do them on the 2.x branch, as, with named arguments in PHP 8, this would be a BC break (name changes). While it could be considered a bugfix, it would potentially break code for users. So let's do it here; I'll push those shortly. |
- `ServerRequest` `getAttribute` and `withAttribute` methods: rename `$attribute` to `$name`. - `StreamFactory::createStreamFromFile()`: rename `$file` to `$filename` Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney thank you! |
Description
This patch adapts Diactoros to work with either PSR-7 v1.1 or v2.0 by explicitly adding the parameter type hints defined in PSR-7 v2.0, as well as
void
return type declarations where not previously declared.This patch depends on the following upstream changes:
psr/http-message
v2 php-fig/http-factory#13 (will likely be tagged 1.1)This patch should be applied to an upcoming 3.0.x branch, for release as 3.0, due to the following BC breaks:
void
in the PSR-7 spec that we had not marked in our own implementation with avoid
return declaration leads to the BC break, as updating our implementation means extensions that do not declare it will now cause a fatal error.Tasks
The following are required before removing this from draft status: