mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 23:32:17 +00:00
Added \JsonSerializable interface to Response->json (issue: #284).
This commit is contained in:
@@ -69,13 +69,19 @@ class Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json encode array
|
* Json encode
|
||||||
* @param array $value
|
* @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');
|
$this->header('Content-type: application/json');
|
||||||
echo json_encode($value);
|
echo json_encode($value);
|
||||||
die();
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user