From 3856b671aa043804c393566e8febb2288978a80c Mon Sep 17 00:00:00 2001 From: sundowndev Date: Sun, 8 Jul 2018 21:46:25 +0200 Subject: [PATCH] Json response service --- server/src/Service/JsonResponse.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/src/Service/JsonResponse.php b/server/src/Service/JsonResponse.php index 4079dc8..c7d32ec 100644 --- a/server/src/Service/JsonResponse.php +++ b/server/src/Service/JsonResponse.php @@ -4,13 +4,17 @@ namespace App\Service; class JsonResponse { - public function create(array $data, $code) + public function create(int $code, string $message = null, array $data = []) { - $response = json_encode($data); + $response = [ + 'code' => $code, + 'message' => $message, + 'data' => $data + ]; header('Content-Type: application/json'); http_response_code($code); - return $response; + return json_encode($response); } } \ No newline at end of file