From 4248eababee094cfbd117d6842fbac72d4b86fb5 Mon Sep 17 00:00:00 2001 From: cranetm Date: Tue, 17 Jan 2017 08:55:04 +0200 Subject: [PATCH] Default response object was removed(['success' => true]). --- JsonRpc2/Controller.php | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/JsonRpc2/Controller.php b/JsonRpc2/Controller.php index 37d67a4..29aca27 100644 --- a/JsonRpc2/Controller.php +++ b/JsonRpc2/Controller.php @@ -68,7 +68,7 @@ public function runAction($id, $params = []) * @param $requestObject * @throws \Exception * @throws \yii\web\HttpException - * @return Response + * @return Response|array|null */ private function getActionResponse($requestObject) { @@ -358,11 +358,6 @@ private function parseMethodDocComment($method) } } - /** @var array Use as 'result' when method returns null */ - private static $defaultResult = [ - "success" => true - ]; - /** * Formats and returns * @param null $result @@ -372,21 +367,16 @@ private function parseMethodDocComment($method) */ public function formatResponse($result = null, Exception $error = null, $id = null) { - $resultKey = 'result'; - - if (!empty($error)) { - $resultKey = 'error'; - $resultValue = $error->toArray(); - } - else if (null === $result) - $resultValue = self::$defaultResult; - else - $resultValue = $result; - - return [ + $resultArray = [ 'jsonrpc' => '2.0', - $resultKey => $resultValue, 'id' => $id, ]; + + if (!empty($error)) + $resultArray['error'] = $error->toArray(); + else + $resultArray['result'] = $result; + + return $resultArray; } }