-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Clarify how to handle response bodies and add withStringBody docs #4771
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
Conversation
en/controllers/request-response.rst
Outdated
|
|
||
| .. php:method:: withBody($body) | ||
| To set the response body, use the `withBody()` method, which is provided by the |
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.
Backticks for inline code need to be doubled up.
en/controllers/request-response.rst
Outdated
|
|
||
| .. php:method:: withStringBody($string) | ||
| In most use cases, it is simpler to set a string as the response body:: |
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.
If it is simpler, why not put it first?
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.
true :)
en/controllers/request-response.rst
Outdated
| // Set a string into the body | ||
| $response = $response->withStringBody('My Body'); | ||
|
|
||
| //If you want a json response |
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.
Nitpicking: Space after double slashes.
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.
Not nitpicking. Thoroughly 👍
en/controllers/request-response.rst
Outdated
| .. versionadded:: 3.4.3 | ||
| `withStringBody()` was added in 3.4.3 | ||
|
|
||
| You can also stream responses from files using diactoros streams:: |
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.
Isn't diactoros a name? Using a capital letter "Diactoros", could make it more clear for non English native speakers...
en/controllers/request-response.rst
Outdated
| $stream = new Stream('/path/to/file', 'rb'); | ||
| $response = $response->withBody($stream); | ||
|
|
||
| You can also stream responses from a callback using the ``CallbackStream`` this |
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.
"CallbackStream. This"
en/controllers/request-response.rst
Outdated
|
|
||
| // If you want a json response | ||
| $response = $response->withType('application/json') | ||
| ->withBody(json_encode(['Foo' => 'bar'])); |
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.
Should be withStringBody I guess...
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.
Yes, thx :)
en/controllers/request-response.rst
Outdated
| ->withStringBody(json_encode(['Foo' => 'bar'])); | ||
|
|
||
| .. versionadded:: 3.4.3 | ||
| `withStringBody()` was added in 3.4.3 |
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.
Another place backticks need to be doubled.
en/controllers/request-response.rst
Outdated
| // Prior to 3.4.0 - Set the body | ||
| $this->response->body('My Body'); | ||
|
|
||
| Be sure that `$stream` is a :php:class:`Psr\\Http\\Message\\StreamInterface` object. |
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.
Here too.
I tried to clarify the use of
withBody().I also fixed some mistakes and restructured the response section a bit.