Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

robertprice
Copy link
Contributor

@robertprice robertprice commented Sep 1, 2016

Fixes issue #1818. The withJson method now clones the Response, and
updates this with a new header, and a new Body.

Fixes issue 1818. The withJson method now clones the Response, and
updates this with a new header, and a new Body.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.18% when pulling 768306f on robertprice:1818 into 1dedd25 on slimphp:3.x.

$body->rewind();
$body->write($json = json_encode($data, $encodingOptions));
$clone = clone $this;
$clone->body = new Body(fopen('php://temp', 'w+'));
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

@mathmarques mathmarques Sep 2, 2016

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.

Copy link
Contributor Author

@robertprice robertprice Sep 2, 2016

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.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.002%) to 97.178% when pulling 404321f on robertprice:1818 into 1dedd25 on slimphp:3.x.

@robertprice
Copy link
Contributor Author

Merging #1978 will fix the php7 failing tests.

@akrabat akrabat closed this in 0899bcb Oct 11, 2016
@akrabat
Copy link
Member

akrabat commented Oct 11, 2016

Thanks!

@akrabat akrabat added this to the 3.6.0 milestone Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants