Skip to content

Commit

Permalink
Default response object was removed(['success' => true]).
Browse files Browse the repository at this point in the history
  • Loading branch information
cranetm committed Jan 17, 2017
1 parent 89b3d75 commit 4248eab
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions JsonRpc2/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}

0 comments on commit 4248eab

Please sign in to comment.