1 | <?php |
||
18 | class S3BucketStreamZip |
||
19 | { |
||
20 | /** |
||
21 | * @var array |
||
22 | * |
||
23 | * http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html |
||
24 | * |
||
25 | * { |
||
26 | * key: access key, |
||
27 | * secret: access secret |
||
28 | * bucket: bucket name |
||
29 | * region: bucket region |
||
30 | * prefix: prefix |
||
31 | * } |
||
32 | */ |
||
33 | private $params = []; |
||
34 | |||
35 | /** |
||
36 | * @var object |
||
37 | */ |
||
38 | private $s3Client; |
||
39 | |||
40 | /** |
||
41 | * Create a new ZipStream object. |
||
42 | * |
||
43 | * @param array $params - AWS key, secret, region, and list object parameters |
||
44 | */ |
||
45 | 4 | public function __construct($params) |
|
46 | { |
||
47 | 4 | foreach (['key', 'secret', 'bucket', 'region'] as $key) { |
|
48 | 4 | if (!isset($params[$key])) { |
|
49 | 3 | throw new InvalidParameterException('$params parameter to constructor requires a `'.$key.'` attribute'); |
|
50 | } |
||
51 | 3 | } |
|
52 | |||
53 | 1 | $this->params = $params; |
|
54 | |||
55 | 1 | $this->s3Client = new S3Client( |
|
56 | [ |
||
57 | 1 | 'region' => $this->params['region'], |
|
58 | 1 | 'version' => 'latest', |
|
59 | 'credentials' => [ |
||
60 | 1 | 'key' => $this->params['key'], |
|
61 | 1 | 'secret' => $this->params['secret'], |
|
62 | 1 | ], |
|
63 | 1 | ]); |
|
64 | 1 | } |
|
65 | |||
66 | /** |
||
67 | * Stream a zip file to the client. |
||
68 | * |
||
69 | * @param string $filename - Name for the file to be sent to the client |
||
70 | * @param array $params - Optional parameters |
||
71 | * { |
||
72 | * expiration: '+10 minutes' |
||
73 | * } |
||
74 | */ |
||
75 | public function send($filename, $params = []) |
||
131 | } |
||
132 |