-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Psr\Http\Message\ServerRequestInterface
applied for yii\web\Request
#15416
Conversation
*/ | ||
public function setBodyParams($values) | ||
public function setParsedBody($values) |
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.
Do we still need to have setParsedBody()
as public?
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.
I would rather keep it, since it was there before.
Besides having such public method can be useful while writing unit tests.
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.
since it was there before.
That's not a good reason for a BC breaking release. As far as I understand PSR, whole idea is to make Request immutable i.e. no setters.
* @param array $serverParams server parameters. | ||
* @since 2.1.0 | ||
*/ | ||
public function setServerParams(array $serverParams) |
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.
There are with*
methods for everything but serverParams
. I think it makes sense to make it uniform having only with*
public methods.
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.
All with*
methods are dictated by PSR. Since PSR does not provide withServerParams()
method, I see no reason for implementing it. If you find this inconsistent you should report it to PHPFig.
Usage of with*
methods is uneffective, since it causes object cloning. While configuring single Request
instance via with*
methods you will have it cloned 5-10 times.
Yii behaviors and filters would be unable to function via immutable setters as they may need to adjust passing Request
or Response
without being able to re-set thier origin.
Also keep in mind that while being cloned every instance of yii\base\Component
, which Request
is, looses any event handlers or behaviors (filters) attached to it.
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.
Also keep in mind that removing setters in favor of with*
methods will make impossible to configure Request
instance via DI, even with the recent features from yiisoft/di
. For example:
[
'__class' => 'yii\web\Request',
'withCookieParams' => [....], // have no effect: calls `$request->withCookieParams()`, but looses returned new instance
]
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.
The whole idea of the PSR is that Request object should be created once (passing everything needed in constructor) and then not being modified again except cloning via with
.
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.
If you sure in which way it should be - feel free to make modifications.
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.
Do we have any request behaviors currently?
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.
Losing event handlers could be a problem. Need to check code again before I suggest anything...
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.
Currently Request doesn't trigger anything and there are no known behaviors for it.
* @param array $cookies array of key/value pairs representing cookies. | ||
* @since 2.1.0 | ||
*/ | ||
public function setCookieParams(array $cookies) |
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.
Do we need it public?
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.
See #15416 (comment)
@@ -1753,6 +1871,17 @@ public function setUploadedFiles($uploadedFiles) | |||
$this->_uploadedFiles = $uploadedFiles; |
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.
Do we need it public?
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.
See #15416 (comment)
/** | ||
* @param array $attributes attributes derived from the request. | ||
*/ | ||
public function setAttributes(array $attributes) |
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.
Do we need it public?
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.
See #15416 (comment)
* @return array attributes derived from the request. | ||
* @since 2.1.0 | ||
*/ | ||
protected function defaultAttributes() |
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.
What's the usecase?
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.
According to PSR request attributes are determined by particular Request
class logic.
Having separated method allows developer to define internal attributes while extending yii\web\Request
without necessity of re-defining private field for thier actual storage.
Currently Request serves many responsibilities:
The idea of PSR-7 is immutability and it makes sense in request/response paradigm. After request is received and PSR-7 request object is created, it's set in stone. Attempt to modify it usually means a possible bug. It makes sens to have multiple classes:
|
PR merged as an intermediate solution. |
OK. Thanks. |
Fixing
yii\web\Request
to implementPsr\Http\Message\ServerRequestInterface
instead of justPsr\Http\Message\RequestInterface