private function getBodyToSend() { if (!empty($this->Serializer) && $this->body !== '') { $body = $this->Serializer->serialize($this->body); if ($this->Serializer->getContentType()) { $this->setHeader('Content-Type', $this->Serializer->getContentType()); } return $body; } else { $body = $this->body; if (!is_scalar($body)) { $Serializer = new SerializerJSON(); $body = $Serializer->serialize($body); $this->setHeader('Content-Type', $Serializer->getContentType()); $this->setHeader('X-Warning', 'Result of request should be serialized to send through. Specify in "ACCEPT" header type of acceptable method of serialization.'); return $body; } return $body; } }
/** * Serializes the current object. * * @param ISerializer $serializer The serializer. * * @return string * * @throws \InvalidArgumentException */ public function serialize($serializer) { $serialized = Resources::EMPTY_STRING; if ($serializer instanceof XmlSerializer) { $arr = $this->toArray(); $serialized = $serializer->serialize($arr, $this->_serializationProperties); } else { throw new \InvalidArgumentException(Resources::UNKNOWN_SRILZER_MSG); } return $serialized; }