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\Message\Response;
 7: 
 8: 
 9: /**
10:  * Response class for endpoints that return binary zip files.
11:  */
12: class ZipResponse extends RawResponse implements ResponseClassInterface {
13:     
14:     /**
15:      * @var \ZipArchive
16:      */
17:     private $zip;
18:     
19: 
20:     /**
21:      * Create a response model object from a completed command
22:      * @param OperationCommand Command that serialized the request
23:      * @return ZipResponse
24:      */
25:     public static function fromCommand( OperationCommand $command ) {
26:         $response = $command->getResponse();
27:         $me = new self;
28:         return $me->init( $response );
29:     }
30:     
31:     
32:     /**
33:      * Get zip archive instance.
34:      * @throws \Exception if zip file is invalid
35:      * @return \ZipArchive
36:      */
37:     public function getZip(){
38:         if( ! $this->zip ){
39:             // temporary file required for opening zip
40:             $tmp = tempnam( sys_get_temp_dir(), 'loco_zip_' );
41:             register_shutdown_function( 'unlink', $tmp );
42:             file_put_contents( $tmp, $this->__toString() );
43:             $this->zip = new \ZipArchive;
44:             if( ! $this->zip->open( $tmp, \ZipArchive::CHECKCONS ) ){
45:                 throw new \Exception('Failed to open zip archive from response data');
46:             }
47:         }
48:         return $this->zip;
49:     }   
50:      
51: 
52: }
Loco SDK - PHP API documentation generated by ApiGen 2.8.0