We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
public function withJson($data, $status = 200, $encodingOptions = 0) { $body = $this->getBody(); $body->rewind(); $body->write(json_encode($data, $encodingOptions)); return $this->withStatus($status)->withHeader('Content-Type', 'application/json;charset=utf-8'); }
Yes, withJson() is not part of PSR-7, but the naming suggests that it works like the other PSR-7 compliant methods.
withJson()
I expected $response->withStatus(500)->withJson([ ... ]) to not override my status code.
$response->withStatus(500)->withJson([ ... ])
Granted, I could use it as $response->withJson([...], 500) which to be honest I did not know about until I stumbled across this.
$response->withJson([...], 500)
I feel like the naming strongly suggests the usual PSR-7 "cloning and keep your properties"-behaviour and suggest keeping the status code:
public function withJson($data, $status = null, $encodingOptions = 0) { $body = $this->getBody(); $body->rewind(); $body->write(json_encode($data, $encodingOptions)); $status = is_null($status) ? $this->getStatusCode() : null; return $this->withStatus($status)->withHeader('Content-Type', 'application/json;charset=utf-8'); }
What do you think?
TL;DR withJson is not part of PSR-7 but is named like a PSR-7 compliant method and therefore should not override a response's status code
withJson
The text was updated successfully, but these errors were encountered:
This has already been fixed in #1737 and will be available in version 3.2.
Sorry, something went wrong.
No branches or pull requests
Yes,
withJson()
is not part of PSR-7, but the naming suggests that it works like the other PSR-7 compliant methods.I expected
$response->withStatus(500)->withJson([ ... ])
to not override my status code.Granted, I could use it as
$response->withJson([...], 500)
which to be honest I did not know about until I stumbled across this.I feel like the naming strongly suggests the usual PSR-7 "cloning and keep your properties"-behaviour and suggest keeping the status code:
What do you think?
TL;DR
withJson
is not part of PSR-7 but is named like a PSR-7 compliant method and therefore should not override a response's status codeThe text was updated successfully, but these errors were encountered: