Example #1
0
 /**
  * @param AbstractResponse $response The response to be encoded.
  * @return string Returns the response encoded as a string.
  */
 public function encode(AbstractResponse $response)
 {
     if (is_string($response->getResponseObject())) {
         return $response->getResponseObject();
     } else {
         return '';
     }
 }
 /**
  * @param AbstractResponse $response The response to be encoded.
  * @return string Returns the response encoded as a string.
  */
 public function encode(AbstractResponse $response)
 {
     $responseObject = $response->getResponseObject();
     if (is_string($responseObject)) {
         return $responseObject;
     } else {
         return $this->viewEnvironment->loadTemplate($this->template)->render((array) $responseObject);
     }
 }
Example #3
0
 /**
  * @param AbstractResponse $response The response to be encoded.
  * @return (string) Returns the response encoded as a string.
  */
 public function encode(AbstractResponse $response)
 {
     $responseObject = $response->getResponseObject();
     if (null === $responseObject || is_array($responseObject) || is_scalar($responseObject)) {
         return json_encode($responseObject);
     } elseif (is_object($responseObject)) {
         if (method_exists($responseObject, 'jsonSerialize')) {
             return json_encode($responseObject->jsonSerialize());
         } else {
             return json_encode(get_object_vars($responseObject));
         }
     } else {
         throw new EncoderException('Unable to encode response as JSON.');
     }
 }