serializer = $serializer; $this->contentTypeJson(); } public function responseClass($class) { $this->responseClass = $class; } /** * @return PObjectCurlResponse */ public function call($method, $url, $payload = '') { $payload = $this->serialize($payload); $response = parent::call($method, $url, $payload); $object = $this->deserialize($response->getBody()); return new PObjectCurlResponse($response->getHeader(), $response->getBody(), $response->getHttpCode(), $object); } private function serialize($payload) { try { return empty($payload) ? $payload : $this->serializer->serialize($payload, 'json'); } catch (RuntimeException $e) { throw new PCurlException(sprintf('Unable to serialize payload - %s : %s', $e->getMessage(), $payload)); } } private function deserialize($response) { if (empty($this->responseClass)) { return $response; } try { return $this->responseClass ? $this->serializer->deserialize($response, $this->responseClass, 'json') : $response; } catch (RuntimeException $e) { throw new PCurlException(sprintf('Unable to deserialize response - %s : %s', $e->getMessage(), $response)); } } }