Overview

Namespaces

  • Loco
    • Http
      • Response

Classes

  • RawResponse
  • ZipResponse
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace Loco\Http\Response;
 3: 
 4: use Guzzle\Service\Command\ResponseClassInterface;
 5: use Guzzle\Service\Command\OperationCommand;
 6: use Guzzle\Http\Exception\BadResponseException;
 7: use Guzzle\Http\Message\Response;
 8: 
 9: 
10: /**
11:  * Response class for endpoints that return raw, unstructured data that will not be unserialized.
12:  */
13: class RawResponse implements ResponseClassInterface {
14: 
15:     private $source;
16: 
17:     /**
18:      * Create a response model object from a completed command
19:      * @param OperationCommand Command that serialized the request
20:      * @throws BadResponseException 
21:      * @return RawResponse
22:      */
23:     public static function fromCommand( OperationCommand $command ) {
24:         $response = $command->getResponse();
25:         if( 204 === $response->getStatusCode() ){
26:             throw new \Exception('Response contains no data');
27:         }
28:         $me = new self;
29:         return $me->init( $response );
30:     }
31:     
32:     
33:     /**
34:      * Initialize from http response
35:      * @internal
36:      * @return RawResponse
37:      */
38:     protected function init( Response $response ){
39:         $this->source = $response->getBody()->__toString();
40:         return $this;
41:     }  
42:     
43:     
44:     /**
45:      * Get raw data.
46:      * @return string
47:      */
48:     public function __toString(){
49:         return $this->source;
50:     }
51: 
52: }
Loco SDK - PHP API documentation generated by ApiGen 2.8.0