Expand ResponseFactory
authorTim Starling <tstarling@wikimedia.org>
Tue, 4 Jun 2019 05:52:19 +0000 (15:52 +1000)
committerTim Starling <tstarling@wikimedia.org>
Wed, 12 Jun 2019 00:22:34 +0000 (10:22 +1000)
commit0ae06654d764c82a54c85d3bd7a080b9f2c57ecc
treef23d9b3628e1e707f30c660319eb83842fa48c5d
parent3f0056a252daa4e97396e0eb4b72651f33ce57b3
Expand ResponseFactory

* Factor out json_encode() call into ResponseFactory::encodeJson().
* Add createJson() and standardize on JSON for 4xx and 5xx responses
* Add methods for redirect generation, providing an HTML link in the
  body as recommended by RFC 7231

Most of the code was written by GergÅ‘ Tisza. The differences compared to
I747e34faecbcd are:

* Remove JsonResponse.
* Swap parameter order of createJson() reflecting the fact that the
  value is now usually provided.
* Remove unnecessary ResponseFactory::setStatus()
* Don't do ['code' => 'http500'] by default, use httpCode and httpReason
  to provide that information
* In createFromReturnValue(), don't wrap numerically-indexed arrays.
* Added tests.

Bug: T223240
Change-Id: Ie185b2bd43690633f1ccbe6328a0518e43a9f2f9
includes/Rest/ResponseFactory.php
includes/Rest/Router.php
tests/phpunit/includes/Rest/ResponseFactoryTest.php [new file with mode: 0644]