Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

Conversation

nicolas-grekas
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15414
License MIT
Doc PR -

@stof
Copy link
Member

stof commented Jul 30, 2015

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));
Copy link
Member

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)

@wouterj
Copy link
Member

wouterj commented Jul 30, 2015

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 failSafeHandle, which will be quite a struggle as it's a private method...

@nicolas-grekas
Copy link
Member Author

@wouterj there is no need to reach this code. It's an implementation detail that is kept only for BC.

@nicolas-grekas
Copy link
Member Author

@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)
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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.

@nicolas-grekas nicolas-grekas force-pushed the debug-psr7 branch 3 times, most recently from f5d0016 to 87d2b74 Compare July 31, 2015 07:23
@nicolas-grekas
Copy link
Member Author

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.
PSR-7 being interfaces only (+ immutability) means that for creating a response, you must start from some implementation, then use it as a prototype.
It's not a hard stand and I'm ok to change my mind about that, but this is my preference.

@nicolas-grekas
Copy link
Member Author

An other way to PSR-7 support is to remove HttpFoundation support by deprecating createResponse!
The method is not used by Symfony itself.

@stof
Copy link
Member

stof commented Jul 31, 2015

@nicolas-grekas what is the use case of this method actually ?

@nicolas-grekas
Copy link
Member Author

That's a good question :) @fabpot any idea?

@fabpot
Copy link
Member

fabpot commented Jul 31, 2015

Let's deprecate this method in 2.8 and remove it in 3.0.

@fabpot
Copy link
Member

fabpot commented Jul 31, 2015

So, you need to remove the only usage of it.

@nicolas-grekas
Copy link
Member Author

Fine, closed in favor of #15418

@nicolas-grekas nicolas-grekas deleted the debug-psr7 branch July 31, 2015 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants