0e5ac97ee2
This PR was merged into the 3.1-dev branch.
Discussion
----------
[FrameworkBundle] [DX] Add `Controller::json` method to make it easy to send json
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Its currently a awkward to use Serializer component to send a `JsonResponse`.
I have tried two approaches
1. use `Serializer::normalize` and `JsonResponse`
1. use `Serializer::serialize` and a plain `Response`, and set the `content-type`
In either cases there is need for a custom `json` function so as not to repeat yourself and there are disadvantages.
1. In the first case you are only partly using `Serializer` and any custom `Encoder` would be skipped
1. In the second you are not making use of `JsonResponse`, particular disadvantage if you want to support JSONP.
This new `json` method uses the serializer component is enabled it is used to generate the json data, and falls back to normal `JsonResponse` when its not.
Commits
-------
|
||
---|---|---|
.. | ||
File | ||
Session | ||
AcceptHeaderItemTest.php | ||
AcceptHeaderTest.php | ||
ApacheRequestTest.php | ||
BinaryFileResponseTest.php | ||
CookieTest.php | ||
ExpressionRequestMatcherTest.php | ||
FileBagTest.php | ||
HeaderBagTest.php | ||
IpUtilsTest.php | ||
JsonResponseTest.php | ||
ParameterBagTest.php | ||
RedirectResponseTest.php | ||
RequestMatcherTest.php | ||
RequestStackTest.php | ||
RequestTest.php | ||
ResponseHeaderBagTest.php | ||
ResponseTest.php | ||
ResponseTestCase.php | ||
ServerBagTest.php | ||
StreamedResponseTest.php |