Repository navigation
Expand file tree
/
Copy pathS3.php
More file actions
executable file
·426 lines (393 loc) · 13.4 KB
/
Copy pathS3.php
File metadata and controls
executable file
·426 lines (393 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?php
/**
* Webiny Framework (http://www.webiny.com/framework)
*
* @copyright Copyright Webiny LTD
*/
namespace Webiny\Component\Amazon;
use Webiny\Component\Amazon\S3\RuntimeException;
use Webiny\Component\Amazon\S3\S3ClientInterface;
use Webiny\Component\StdLib\ComponentTrait;
/**
* S3 Client Component - Amazon S3 Client
*
* @package Webiny\Component\Amazon
*/
class S3 implements S3ClientInterface
{
use ComponentTrait;
/**
* @var array Default configuration params.
*/
private static $defaultConfig = [
'Bridge' => Bridge\S3\S3::class
];
/**
* @var Bridge\S3\S3
*/
private $instance;
/**
* @param $accessKeyId
* @param $secretAccessKey
* @param $region
* @param $endpoint
*/
public function __construct($accessKeyId, $secretAccessKey, $region, $endpoint = null)
{
$bridgeClass = $this->getConfig()->get('Bridge');
$this->instance = new $bridgeClass($accessKeyId, $secretAccessKey, $region, $endpoint);
}
/**
* Get object identified by bucket and key
*
* @param string $bucket
* @param string $key
* @param array $params
*
* @return mixed
*/
public function getObject($bucket, $key, array $params = [])
{
return $this->instance->getObject($bucket, $key, $params);
}
/**
* Get access control policy for the bucket
*
* @param string $bucket
*
* @return mixed
*/
public function getBucketAcl($bucket)
{
return $this->instance->getBucketAcl($bucket);
}
/**
* Deletes the bucket.
* All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket itself can be deleted.
*
* @param $bucket
*
* @return mixed
*/
public function deleteBucket($bucket)
{
return $this->instance->deleteBucket($bucket);
}
/**
* Determines whether or not a bucket exists by name
*
* @param string $bucket The name of the bucket
* @param bool $accept403 Set to true if 403s are acceptable
* @param array $params Additional options to add to the executed command
*
* @return bool
*/
public function doesBucketExist($bucket, $accept403 = true, array $params = [])
{
return $this->instance->doesBucketExist($bucket, $accept403, $params);
}
/**
* Sets the permissions on a bucket using access control lists (ACL).
*
* @param string $bucket
* @param string $acl private | public-read | public-read-write | authenticated-read
*
* @return mixed
*/
public function putBucketAcl($bucket, $acl)
{
return $this->instance->putBucketAcl($bucket, $acl);
}
/**
* Get array of buckets
* Available keys: Name, CreationDate
*
* @return mixed
*/
public function getListBucketsIterator()
{
return $this->instance->getListBucketsIterator();
}
/**
* Set the access control list (ACL) permissions for an object that already exists in a bucket
*
* @param string $bucket
* @param string $key
* @param string $acl private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control
*
* @return mixed
*/
public function putObjectAcl($bucket, $key, $acl)
{
return $this->instance->putObjectAcl($bucket, $key, $acl);
}
/**
* Deletes objects from Amazon S3 that match the result of a ListObjects operation. For example, this allows you
* to do things like delete all objects that match a specific key prefix.
*
* @param string $bucket Bucket that contains the object keys
* @param string $prefix Optionally delete only objects under this key prefix
* @param string $regex Delete only objects that match this regex
* @param array $options Options used when deleting the object:
* - before_delete: Callback to invoke before each delete. The callback will receive a
* Guzzle\Common\Event object with context.
*
* @see Aws\S3\S3Client::listObjects
* @see Aws\S3\Model\ClearBucket For more options or customization
* @return int Returns the number of deleted keys
* @throws RuntimeException if no prefix and no regex is given
*/
public function deleteMatchingObjects($bucket, $prefix = '', $regex = '', array $options = [])
{
return $this->instance->deleteMatchingObjects($bucket, $prefix, $regex, $options);
}
/**
* Returns the region the bucket resides in.
*
* @param string $bucket
*
* @return mixed
*/
public function getBucketLocation($bucket)
{
return $this->instance->getBucketLocation($bucket);
}
/**
* Restores an archived copy of an object back into Amazon S3
*
* @param string $bucket
* @param string $key
* @param int $days
*
* @internal param array $args
*
* @return mixed
*/
public function restoreObject($bucket, $key, $days)
{
return $this->instance->restoreObject($bucket, $key, $days);
}
/**
* Get objects iterator
*
* @param string $bucket
*
* @param array $params
*
* @return mixed
*/
public function getListObjectsIterator($bucket, array $params = [])
{
return $this->instance->getListObjectsIterator($bucket, $params);
}
/**
* Returns some or all (up to 1000) of the objects in a bucket.
* You can use the request parameters as selection criteria to return a subset of the objects in a bucket.
*
* @param string $bucket
*
* @param array $params
*
* @return mixed
*/
public function listObjects($bucket, array $params = [])
{
return $this->instance->listObjects($bucket, $params);
}
/**
* Helper used to clear the contents of a bucket. Use the {@see ClearBucket} object directly
* for more advanced options and control.
*
* @param string $bucket Name of the bucket to clear.
*
* @return int Returns the number of deleted keys
*/
public function clearBucket($bucket)
{
return $this->instance->clearBucket($bucket);
}
/**
* Removes the null version (if there is one) of an object and inserts a delete marker, which becomes the latest version of the object.
* If there isn't a null version, Amazon S3 does not remove any objects.
*
* @param string $bucket
* @param string $key
* @param array $params
*
* @return mixed
*/
public function deleteObject($bucket, $key, array $params = [])
{
return $this->instance->deleteObject($bucket, $key, $params);
}
/**
* Adds an object to a bucket.
*
* @param string $bucket
* @param string $key
* @param string $content
* @param array $params
*
* @return mixed
*/
public function putObject($bucket, $key, $content, array $params = [])
{
return $this->instance->putObject($bucket, $key, $content, $params);
}
/**
* Creates a new bucket.
*
* @param string $bucket
* @param array $params
*
* @return mixed
*/
public function createBucket($bucket, array $params = [])
{
return $this->instance->createBucket($bucket, $params);
}
/**
* Recursively uploads all files in a given directory to a given bucket.
*
* @param string $directory Full path to a directory to upload
* @param string $bucket Name of the bucket
* @param string $keyPrefix Virtual directory key prefix to add to each upload
* @param array $options Associative array of upload options
* - params: Array of parameters to use with each PutObject operation performed during the transfer
* - base_dir: Base directory to remove from each object key
* - force: Set to true to upload every file, even if the file is already in Amazon S3 and has not changed
* - concurrency: Maximum number of parallel uploads (defaults to 10)
* - debug: Set to true or an fopen resource to enable debug mode to print information about each upload
* - multipart_upload_size: When the size of a file exceeds this value, the file will be uploaded using a
* multipart upload.
*
* @see Aws\S3\S3Sync\S3Sync for more options and customization
*/
public function uploadDirectory($directory, $bucket, $keyPrefix = null, array $options = [])
{
$this->instance->uploadDirectory($directory, $bucket, $keyPrefix, $options);
}
/**
* Creates a copy of an object that is already stored in Amazon S3.
*
* @param string $sourceBucket
* @param string $sourceKey
* @param string $targetBucket
* @param string $targetKey
* @param array $params
*
* @return mixed
*/
public function copyObject($sourceBucket, $sourceKey, $targetBucket, $targetKey, array $params = [])
{
return $this->instance->copyObject($sourceBucket, $sourceKey, $targetBucket, $targetKey, $params);
}
/**
* Determines whether or not an object exists by name
*
* @param string $bucket The name of the bucket
* @param string $key The key of the object
* @param array $params Additional options to add to the executed command
*
* @return bool
*/
public function doesObjectExist($bucket, $key, array $params = [])
{
return $this->instance->doesObjectExist($bucket, $key, $params);
}
/**
* Returns the policy of a specified bucket.
*
* @param string $bucket
*
* @return mixed
*/
public function getBucketPolicy($bucket)
{
return $this->instance->getBucketPolicy($bucket);
}
/**
* Returns the access control list (ACL) of an object.
*
* @param $bucket
* @param $key
*
* @return mixed
*/
public function getObjectAcl($bucket, $key)
{
return $this->instance->getObjectAcl($bucket, $key);
}
/**
* This operation enables you to delete multiple objects from a bucket using a single HTTP request.
* You may specify up to 1000 keys.
*
* @param string $bucket
* @param array $objects
*
* @return mixed
*/
public function deleteObjects($bucket, array $objects)
{
return $this->instance->deleteObjects($bucket, $objects);
}
/**
* Returns a list of all buckets owned by the authenticated sender of the request.
* Available keys: Name, CreationDate
* @return mixed
*/
public function listBuckets()
{
return $this->instance->listBuckets();
}
/**
* Returns the URL to an object identified by its bucket and key. If an expiration time is provided, the URL will
* be signed and set to expire at the provided time.
*
* @param string $bucket The name of the bucket where the object is located
* @param string $key The key of the object
* @param mixed $expires The time at which the URL should expire
* @param array $args Arguments to the GetObject command. Additionally you can specify a "Scheme" if you would
* like the URL to use a different scheme than what the client is configured to use
*
* @return string The URL to the object
*/
public function getObjectUrl($bucket, $key, $expires = null, array $args = [])
{
return $this->instance->getObjectUrl($bucket, $key, $expires, $args);
}
/**
* Downloads a bucket to the local filesystem
*
* @param string $directory Directory to download to
* @param string $bucket Bucket to download from
* @param string $keyPrefix Only download objects that use this key prefix
* @param array $options Associative array of download options
* - params: Array of parameters to use with each GetObject operation performed during the transfer
* - base_dir: Base directory to remove from each object key when storing in the local filesystem
* - force: Set to true to download every file, even if the file is already on the local filesystem and has not
* changed
* - concurrency: Maximum number of parallel downloads (defaults to 10)
* - debug: Set to true or a fopen resource to enable debug mode to print information about each download
* - allow_resumable: Set to true to allow previously interrupted downloads to be resumed using a Range GET
*/
public function downloadBucket($directory, $bucket, $keyPrefix = '', array $options = [])
{
$this->instance->downloadBucket($directory, $bucket, $keyPrefix, $options);
}
/**
* In case of large files, use the multipartUpload method, so the file is sent in chunks to S3, without the need
* to read the complete file in memory.
*
* @param $bucket
* @param $key
* @param $sourcePath
* @param int $concurrency
*
* @return mixed
*/
public function multipartUpload($bucket, $key, $sourcePath, $concurrency = 1)
{
return $this->instance->multipartUpload($bucket, $key, $sourcePath, $concurrency);
}
}