From 539e905b458116d98185bf9f3d7ccd04b0ba0af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 31 Aug 2017 12:01:49 +0100 Subject: [PATCH] Router->json now accepts either array or \JsonSerializable (issue: #284) --- src/Pecee/Http/Response.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Pecee/Http/Response.php b/src/Pecee/Http/Response.php index c5730f1..45226e9 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); } /**