This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/HttpFoundation/Tests
Fabien Potencier 0e5ac97ee2 feature #17642 [FrameworkBundle] [DX] Add Controller::json method to make it easy to send json (mcfedr)
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
-------

f904a2b Add a Controller function to make it easy to return json
2016-03-03 14:18:37 +01:00
..
File Merge branch '2.3' into 2.7 2016-02-22 17:12:29 +01:00
Session Static code analysis 2016-01-25 19:00:36 +02:00
AcceptHeaderItemTest.php fixed CS 2014-09-22 10:32:35 +02:00
AcceptHeaderTest.php [HttpFoundation] Fix AcceptHeader 2012-11-13 17:18:54 +01:00
ApacheRequestTest.php Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
BinaryFileResponseTest.php Merge branch '2.3' into 2.7 2016-02-28 17:19:47 +01:00
CookieTest.php [HttpFoundation][Cookie] Cookie DateTimeInterface fix 2016-01-14 17:21:08 +01:00
ExpressionRequestMatcherTest.php add expression request matcher tests 2014-03-03 18:30:41 +01:00
FileBagTest.php fixed CS 2014-09-22 10:32:35 +02:00
HeaderBagTest.php removed all @covers annotations 2015-11-01 14:17:24 -08:00
IpUtilsTest.php bug #16177 [HttpFoundation] Fixes /0 subnet handling in IpUtils (ultrafez) 2015-10-19 13:54:32 +02:00
JsonResponseTest.php Add a Controller function to make it easy to return json 2016-03-02 16:31:41 +02:00
ParameterBagTest.php Merge branch '2.8' 2015-11-27 15:23:49 +01:00
RedirectResponseTest.php CS fixes 2014-12-03 20:10:26 +00:00
RequestMatcherTest.php Merge branch '2.5' 2014-09-22 13:59:59 +02:00
RequestStackTest.php Revert "[HttpFoundation] removed test file not related to 2.3" 2014-03-04 08:36:26 +01:00
RequestTest.php Merge branch '3.0' 2016-03-02 16:26:30 +01:00
ResponseHeaderBagTest.php Merge branch '2.3' into 2.7 2015-11-02 21:20:53 +01:00
ResponseTest.php Merge branch '2.3' into 2.7 2015-11-20 18:41:18 +01:00
ResponseTestCase.php added missing license blocks 2013-04-22 06:29:54 +02:00
ServerBagTest.php [HttpFoundation] Do not overwrite the Authorization header if it is already set 2016-01-22 07:46:45 +01:00
StreamedResponseTest.php Replace is_callable checks with type hints 2015-10-05 16:57:27 +02:00