From ae68598024f02145e1c8c377286689d26708fa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 31 Aug 2017 12:03:17 +0100 Subject: [PATCH] Response->json now accepts either array or \JsonSerializable (issue: --- src/Pecee/Http/Response.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Pecee/Http/Response.php b/src/Pecee/Http/Response.php index 0c8625a..03d4c9a 100644 --- a/src/Pecee/Http/Response.php +++ b/src/Pecee/Http/Response.php @@ -1,4 +1,5 @@ header('Content-Type: application/json'); + 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); } /**