Total Complexity | 8 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
17 | class GetCurrentItemVersion extends CommandHandler |
||
18 | { |
||
19 | /** |
||
20 | * Get the current version of an item. |
||
21 | * For a complete reference: |
||
22 | * https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-versioning.html?highlight=versioning%20bucket |
||
23 | * |
||
24 | * @param array $params |
||
25 | * |
||
26 | * @return null|string |
||
27 | * @throws \Exception |
||
28 | */ |
||
29 | public function handle($params = []) |
||
30 | { |
||
31 | $bucketName = $params['bucket']; |
||
32 | $keyName = $params['key']; |
||
33 | |||
34 | $fileInfo = File::getPathInfo($keyName); |
||
35 | $prefix = $fileInfo['dirname'] . $this->client->getPrefixSeparator(); |
||
36 | |||
37 | $results = $this->client->getConn()->listObjectVersions([ |
||
38 | 'Bucket' => $bucketName, |
||
39 | 'Prefix' => $prefix |
||
40 | ]); |
||
41 | |||
42 | if (false === isset($results['Versions'])) { |
||
43 | return null; |
||
44 | } |
||
45 | |||
46 | if ($this->client->hasEncoder()) { |
||
47 | $keyName = $this->client->getEncoder()->encode($keyName); |
||
48 | } |
||
49 | |||
50 | foreach ($results['Versions'] as $result) { |
||
51 | if (true === $result['IsLatest'] and $keyName === $result['Key']) { |
||
52 | return $result['VersionId']; |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param array $params |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function validateParams($params = []) |
||
67 | ); |
||
68 | } |
||
70 |