/** * Processes a response. * * @param Response $response The response object. * @param callable $processor The response processor. * * @return Response The response. */ private function processResponse(Response $response, $processor) { if ($response->ok()) { $result = $processor($response); $response->setResult($result); } return $response; }
/** * Encode a response in json format. * * @param Response $response The response. * * @return string The json encoded response. */ private static function encode(Response $response) { $resp = new stdClass(); $resp->body = $response->body; $resp->statusCode = $response->getStatusCode(); $resp->headers = $response->getHeaders(); return json_encode($resp, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT); }