★ wanayoo — archive 1999 https://github.com/slimphp/Slim/pull/1975Nouvelle recherche | Portail wanayoo
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
Closed

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

@coveralls coveralls commented Sep 1, 2016

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+'));

This comment has been minimized.

@mathmarques

mathmarques Sep 2, 2016
Contributor

I think it's better to use $newResponse = $this->withBody(new Body(fopen('php://temp', 'r+'))) instead of clone and set.

This comment has been minimized.

@akrabat

akrabat Sep 2, 2016
Member

Where does newResponse come from?

I like clone as it's quick.

This comment has been minimized.

@mathmarques

mathmarques Sep 2, 2016 •
Contributor

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.

This comment has been minimized.

@robertprice

robertprice Sep 2, 2016 •
Author Contributor

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

@coveralls coveralls commented Sep 2, 2016

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

@robertprice robertprice commented Sep 2, 2016

Merging #1978 will fix the php7 failing tests.

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

@akrabat 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants