|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Simple S3 package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Mauro Cassani<https://github.com/mauretto78> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Matecat\SimpleS3\Commands\Handlers; |
|
13
|
|
|
|
|
14
|
|
|
use Aws\S3\Exception\S3Exception; |
|
15
|
|
|
use Matecat\SimpleS3\Helpers\File; |
|
16
|
|
|
|
|
17
|
|
|
class GetItemsInAVersionedBucket extends GetItemsInABucket |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Get the list of keys in a versioned bucket. |
|
21
|
|
|
* If 'hydrate' parameter is set to true, an array of hydrated Aws\Result is returned instead. |
|
22
|
|
|
* |
|
23
|
|
|
* @param array $params |
|
24
|
|
|
* |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function handle(array $params = []): array |
|
28
|
|
|
{ |
|
29
|
|
|
$bucketName = $params[ 'bucket' ]; |
|
30
|
|
|
|
|
31
|
|
|
try { |
|
32
|
|
|
$config = [ |
|
33
|
|
|
'Bucket' => $bucketName, |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
if (isset($params[ 'prefix' ])) { |
|
37
|
|
|
// add a final slash to prefix |
|
38
|
|
|
if (false === File::endsWith($params[ 'prefix' ], $this->client->getPrefixSeparator())) { |
|
39
|
|
|
$params[ 'prefix' ] .= $this->client->getPrefixSeparator(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$config[ 'Delimiter' ] = (isset($params[ 'delimiter' ])) ? $params[ 'delimiter' ] : $this->client->getPrefixSeparator(); |
|
43
|
|
|
$config[ 'Prefix' ] = $params[ 'prefix' ]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// 1. If 'exclude-cache' is set, return records always from S3 |
|
47
|
|
|
if (isset($params[ 'exclude-cache' ]) and true === $params[ 'exclude-cache' ]) { |
|
48
|
|
|
return $this->returnItemsFromS3($bucketName, $config, (isset($params[ 'hydrate' ])) ? $params[ 'hydrate' ] : null); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// 2. If the cache is set and there is a prefix, return records from cache |
|
52
|
|
|
if ($this->client->hasCache() and isset($config[ 'Prefix' ])) { |
|
53
|
|
|
return $this->returnItemsFromCache($bucketName, $config, (isset($params[ 'hydrate' ])) ? $params[ 'hydrate' ] : null); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// 3. Otherwise, return records from S3 |
|
57
|
|
|
return $this->returnVersionedItemsFromS3($bucketName, $config, (isset($params[ 'hydrate' ])) ? $params[ 'hydrate' ] : null); |
|
58
|
|
|
} catch (S3Exception $e) { |
|
59
|
|
|
$this->commandHandlerLogger?->logExceptionAndReturnFalse($e); |
|
60
|
|
|
|
|
61
|
|
|
throw $e; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|