Added \JsonSerializable interface to Response->json (issue: #284).

This commit is contained in:
Simon Sessingø
2017-08-31 11:59:58 +01:00
parent 16e326ad9f
commit 2952f6a3b6

View File

@@ -69,13 +69,19 @@ class Response {
}
/**
* Json encode array
* @param array $value
* Json encode
* @param array|\JsonSerializable $value
* @throws \InvalidArgumentException;
*/
public function json(array $value) {
public function json($value) {
if(($value instanceof \JsonSerializable) === false && is_array($value) === false) {
throw new \InvalidArgumentException('Invalid type for parameter "value". Must be of type array or object implementing the \JsonSerializable interface.');
}
$this->header('Content-type: application/json');
echo json_encode($value);
die();
exit(0);
}
/**