Exemple #1
0
 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;
     }
 }
Exemple #2
0
 /**
  * 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;
 }