/** * @param MethodResponse $response * @return Response * @throws \Seven\RpcBundle\Exception\UnknownMethodResponse */ public function createHttpResponse(MethodResponse $response) { $data = array('jsonrpc' => '2.0'); if ($response instanceof MethodReturn) { $data['result'] = $response->getReturnValue(); } elseif ($response instanceof MethodFault) { $data['error'] = array('code' => $response->getCode(), 'message' => $response->getMessage()); } else { throw new UnknownMethodResponse("Unknown MethodResponse instance"); } if ($response->getCallId()) { $data['id'] = $response->getCallId(); } return new Response(json_encode($data), 200, array('content-type' => 'text/json')); }