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: 11:
12: class ZipResponse extends RawResponse implements ResponseClassInterface {
13:
14: 15: 16:
17: private $zip;
18:
19:
20: 21: 22: 23: 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: 34: 35: 36:
37: public function getZip(){
38: if( ! $this->zip ){
39:
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: }