#290 - JSON methods now support encode option/depth, added missing arguments to json/jsonp method documentation, _json/_jsonp methods now list arguments on individual lines to remain PSR-2 compliant

pull/294/head
Shane Armstrong 8 years ago
parent ec24d78602
commit b7b929bf99

@ -887,8 +887,8 @@ Flight::error($exception) // Sends an HTTP 500 response.
Flight::notFound() // Sends an HTTP 404 response.
Flight::etag($id, [$type]) // Performs ETag HTTP caching.
Flight::lastModified($time) // Performs last modified HTTP caching.
Flight::json($data, [$code], [$encode]) // Sends a JSON response.
Flight::jsonp($data, [$param], [$code], [$encode]) // Sends a JSONP response.
Flight::json($data, [$code], [$encode], [$charset], [$encodeOption], [$encodeDepth]) // Sends a JSON response.
Flight::jsonp($data, [$param], [$code], [$encode], [$charset], [$encodeOption], [$encodeDepth]) // Sends a JSONP response.
```
Any custom methods added with `map` and `register` can also be filtered.

@ -452,9 +452,18 @@ class Engine {
* @param int $code HTTP status code
* @param bool $encode Whether to perform JSON encoding
* @param string $charset Charset
* @param int $encodeOption Bitmask Json constant such as JSON_HEX_QUOT
* @param int $encodeDepth Maximum encoding depth, must be greater than 0
*/
public function _json($data, $code = 200, $encode = true, $charset = 'utf-8') {
$json = ($encode) ? json_encode($data) : $data;
public function _json(
$data,
$code = 200,
$encode = true,
$charset = 'utf-8',
$encodeOption = 0,
$encodeDepth = 512
) {
$json = ($encode) ? json_encode($data, $encodeOption, $encodeDepth) : $data;
$this->response()
->status($code)
@ -471,9 +480,19 @@ class Engine {
* @param int $code HTTP status code
* @param bool $encode Whether to perform JSON encoding
* @param string $charset Charset
* @param int $encodeOption Bitmask Json constant such as JSON_HEX_QUOT
* @param int $encodeDepth Maximum encoding depth, must be greater than 0
*/
public function _jsonp($data, $param = 'jsonp', $code = 200, $encode = true, $charset = 'utf-8') {
$json = ($encode) ? json_encode($data) : $data;
public function _jsonp(
$data,
$param = 'jsonp',
$code = 200,
$encode = true,
$charset = 'utf-8',
$encodeOption = 0,
$encodeDepth = 512
) {
$json = ($encode) ? json_encode($data, $encodeOption, $encodeDepth) : $data;
$callback = $this->request()->query[$param];

@ -41,8 +41,8 @@
* @method static \flight\net\Request request() Returns Request instance.
* @method static \flight\net\Response response() Returns Request instance.
* @method static void redirect($url, $code = 303) Redirects to another URL.
* @method static void json($data, $code = 200, $encode = true) Sends a JSON response.
* @method static void jsonp($data, $param = 'jsonp', $code = 200, $encode = true) Sends a JSONP response.
* @method static void json($data, $code = 200, $encode = true, $charset = "utf8", $encodeOption = 0, $encodeDepth = 512) Sends a JSON response.
* @method static void jsonp($data, $param = 'jsonp', $code = 200, $encode = true, $charset = "utf8", $encodeOption = 0, $encodeDepth = 512) Sends a JSONP response.
* @method static void error($exception) Sends an HTTP 500 response.
* @method static void notFound() Sends an HTTP 404 response.
*

Loading…
Cancel
Save