/** Returns a reference to the response content.
  *
  * @return static
  */
 public function invoke()
 {
     if (!$this->hasEncapsulatedObject()) {
         $this->setEncapsulatedObject(JsonApi_Response::factory(new JsonApi_Http_Response(Zend_Uri::factory($this->getBrowser()->getRequest()->getUri()), $this->getBrowser()->getResponse()->getStatusCode(), $this->getBrowser()->getResponse()->getContent())));
     }
     return $this;
 }
Exemplo n.º 2
0
 /** Initialize the response object.
  *
  * @return void
  */
 protected function _initialize()
 {
     parent::_initialize();
     if ($this->getDecodedJson()->status != self::STATUS_OK) {
         throw new JsonApi_Response_Exception(sprintf('Received unexpected "%s" status value for success message.', $this->getDecodedJson()->status));
     }
     $this->_initDetail();
 }
Exemplo n.º 3
0
 /** Init the response object.
  *
  * @throws JsonApi_Response_Exception If response JSON is malformed.
  * @return void
  */
 protected function _initialize()
 {
     parent::_initialize();
     if ($this->getDecodedJson()->status != self::STATUS_FAIL) {
         throw new JsonApi_Response_Exception(sprintf('Received unexpected "%s" status value for failure message.', $this->getDecodedJson()->status));
     }
     $this->_initDetail();
     /* Convert errors into an array. */
     $props = $this->getPropertiesObject();
     $props->set(self::KEY_ERRORS, (array) $props->get(self::KEY_ERRORS));
 }
Exemplo n.º 4
0
 public function testUnparseableResponse()
 {
     $response = JsonApi_Response::factory(new JsonApi_Http_Response($this->_uri, self::HTTP_STATUS_OK, 'This is not JSON.  This is only a tribute.'));
     $this->assertInstanceOf('JsonApi_Response_Error', $response, 'Expected unparseable content to be encapsulated in an error object.');
     /* Since we're here, let's also make sure we can convert the error response
      *  into an exception.
      */
     try {
         $response->throwException();
         $this->fail('Expected JsonApi_Response_RethrownException to be thrown.');
     } catch (JsonApi_Response_RethrownException $e) {
     }
 }
Exemplo n.º 5
0
 /** Creates a JsonApi_Response object from this HTTP response.
  *
  * @return JsonApi_Response
  */
 public function makeJsonApiResponse()
 {
     return JsonApi_Response::factory($this);
 }
Exemplo n.º 6
0
 /** Generates a response object.
  *
  * @param int   $httpStatus
  * @param array $content
  *
  * @return JsonApi_Response
  */
 protected function _genResponse($httpStatus, array $content)
 {
     return JsonApi_Response::factory(new JsonApi_Http_Response($this->_uri, $httpStatus, json_encode($content)));
 }