-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Debug] PSR-7 support #15415
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
[Debug] PSR-7 support #15415
Conversation
nicolas-grekas
commented
Jul 30, 2015
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #15414 |
License | MIT |
Doc PR | - |
Having a method whose return type depends on whether the second argument was provided or no looks weird. Thus, both code paths are not sharing the logic (except for the exception flattening, but this is not a big deal). So I suggest using a different method instead for the PSR7 case (thus, we are modifying a response for PSR7, not creating it). and btw, your implementation actually depends of how the response passed as argument looks like. It might do weird things if it is not a basic empty response. |
->expects($this->exactly(1)) | ||
->method('withStatus') | ||
->with(123) | ||
->will($this->returnValue($response)); |
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.
returning the same mock for the response does not match the PSR-7 behavior, and it means that the test will still pass if you remove one of the assignments of the modified response (or even all of them)
This code also isn't very easy to use, as it's called from: private function failSafeHandle(\Exception $exception)
{
if (class_exists('Symfony\Component\HttpFoundation\Response', false)) {
$response = $this->createResponse($exception);
$response->sendHeaders();
$response->sendContent();
} else {
$this->sendPhpResponse($exception);
}
} So one would need to override this class and |
@wouterj there is no need to reach this code. It's an implementation detail that is kept only for BC. |
@stof OK for the test and new method. But for expecting an empty response, does psr-7 offer any other way? |
*/ | ||
public function createResponse($exception) | ||
public function createResponse($exception, ResponseInterface $response = null) |
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.
It looks really weird to pass a Response here, especially because it's an immutable one.
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.
Hello psr-7, this is how it works. Since you can't instantiate anything, you can only start from a prototype response and play with 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.
well, we could instantiate something if we choose a particular implementation for that.
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.
but that would be a failure of interoperability and psr-7
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.
And I don't think it's really hard for a caller to already have a prototype response.
f5d0016
to
87d2b74
Compare
PR is ready. I did not create a new method, because I prefer not cluttering the class with unused methods, nor can't I find a better name for it. |
87d2b74
to
1f8396a
Compare
An other way to PSR-7 support is to remove HttpFoundation support by deprecating createResponse! |
@nicolas-grekas what is the use case of this method actually ? |
That's a good question :) @fabpot any idea? |
Let's deprecate this method in 2.8 and remove it in 3.0. |
So, you need to remove the only usage of it. |
Fine, closed in favor of #15418 |