-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Ensure withJson returns a new Response #1975
Conversation
Fixes issue 1818. The withJson method now clones the Response, and updates this with a new header, and a new Body.
$body->rewind(); | ||
$body->write($json = json_encode($data, $encodingOptions)); | ||
$clone = clone $this; | ||
$clone->body = new Body(fopen('php://temp', 'w+')); |
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 think it's better to use $newResponse = $this->withBody(new Body(fopen('php://temp', 'r+')))
instead of clone and set.
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.
Where does newResponse
come from?
I like clone as it's quick.
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 was just saying to use withBody, cause if we have a method for return a new response with a new body, we don't need to reimplement 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.
I think @mathmarques makes a good point. withBody clones and sets the body, so it's the same code really. It may make more sense to do this instead of duplicating code.
Changed withJson to use withBody to create a new Response instead of cloning and setting a new body directly.
Merging #1978 will fix the php7 failing tests. |
Thanks! |
Fixes issue #1818. The withJson method now clones the Response, and
updates this with a new header, and a new Body.