From 95ae5608a4d0c2198d4bfaee9821f2a330626113 Mon Sep 17 00:00:00 2001 From: AL EMRAN Date: Wed, 15 Nov 2023 18:54:13 +0600 Subject: [PATCH 1/3] Add dynamic http status for json method --- src/Message/Response.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Message/Response.php b/src/Message/Response.php index edd6245b..a3e5d89a 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -141,10 +141,11 @@ public static function html($html) * ``` * * @param mixed $data + * @param int $status * @return self * @throws \InvalidArgumentException when encoding fails */ - public static function json($data) + public static function json($data, int $status = 200) { $json = @\json_encode( $data, @@ -159,7 +160,7 @@ public static function json($data) ); } - return new self(self::STATUS_OK, array('Content-Type' => 'application/json'), $json . "\n"); + return new self($status, array('Content-Type' => 'application/json'), $json . "\n"); } /** From b2fb88b922044f62863e5813c5ca04a91a32300a Mon Sep 17 00:00:00 2001 From: AL EMRAN Date: Wed, 15 Nov 2023 19:02:02 +0600 Subject: [PATCH 2/3] set status null and handle null --- src/Message/Response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/Response.php b/src/Message/Response.php index a3e5d89a..0c1ad440 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -145,7 +145,7 @@ public static function html($html) * @return self * @throws \InvalidArgumentException when encoding fails */ - public static function json($data, int $status = 200) + public static function json($data, $status = null) { $json = @\json_encode( $data, @@ -160,7 +160,7 @@ public static function json($data, int $status = 200) ); } - return new self($status, array('Content-Type' => 'application/json'), $json . "\n"); + return new self($status ? $status : self::STATUS_OK, array('Content-Type' => 'application/json'), $json . "\n"); } /** From 51fc1929b41e3f3e3f0be8f54089c290550142f0 Mon Sep 17 00:00:00 2001 From: AL EMRAN Date: Thu, 16 Nov 2023 02:11:32 +0600 Subject: [PATCH 3/3] set default value as 200 -Status OK --- src/Message/Response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/Response.php b/src/Message/Response.php index 0c1ad440..513cc4d7 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -141,11 +141,11 @@ public static function html($html) * ``` * * @param mixed $data - * @param int $status + * @param int|null $status * @return self * @throws \InvalidArgumentException when encoding fails */ - public static function json($data, $status = null) + public static function json($data, $status = self::STATUS_OK) { $json = @\json_encode( $data,