From 71343f2f627bccfe248cf07ab2a5fc8e08d338c2 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Sun, 20 Aug 2017 02:32:50 +0700 Subject: [PATCH] Server: Extracted method for emitting response --- src/Server/Helper.php | 11 ++++++++++- src/Server/StandardServer.php | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Server/Helper.php b/src/Server/Helper.php index 3754ae7..1957fec 100644 --- a/src/Server/Helper.php +++ b/src/Server/Helper.php @@ -401,8 +401,17 @@ class Helper private function doSendResponse($result, $exitWhenDone) { $httpStatus = $this->resolveHttpStatus($result); - $body = json_encode($result); + $this->emitResponse($result, $httpStatus, $exitWhenDone); + } + /** + * @param array|\JsonSerializable $jsonSerializable + * @param int $httpStatus + * @param bool $exitWhenDone + */ + public function emitResponse($jsonSerializable, $httpStatus, $exitWhenDone) + { + $body = json_encode($jsonSerializable); header('Content-Type: application/json', true, $httpStatus); echo $body; diff --git a/src/Server/StandardServer.php b/src/Server/StandardServer.php index 80b1be3..1dcf424 100644 --- a/src/Server/StandardServer.php +++ b/src/Server/StandardServer.php @@ -1,6 +1,7 @@ [ + FormattedError::createFromException($error, $debug) + ] + ]; + $helper = new Helper(); + $helper->emitResponse($response, 500, $exitWhenDone); + } + /** * Creates new instance of a standard GraphQL HTTP server *