| Total Complexity | 5 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 75% |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class EnableAcceleration extends CommandHandler |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Enable acceleration for a bucket. |
||
| 22 | * For a complete reference: |
||
| 23 | * https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-accelerate-configuration.html |
||
| 24 | * |
||
| 25 | * @param array $params |
||
| 26 | * |
||
| 27 | * @return bool |
||
| 28 | * @throws Exception |
||
| 29 | */ |
||
| 30 | 1 | public function handle(array $params = []): bool |
|
| 31 | { |
||
| 32 | 1 | $bucketName = $params[ 'bucket' ]; |
|
| 33 | |||
| 34 | try { |
||
| 35 | 1 | $accelerate = $this->client->getConn()->putBucketAccelerateConfiguration( |
|
| 36 | 1 | [ |
|
| 37 | 1 | 'AccelerateConfiguration' => [ |
|
| 38 | 1 | 'Status' => 'Enabled', |
|
| 39 | 1 | ], |
|
| 40 | 1 | 'Bucket' => $bucketName, |
|
| 41 | 1 | ] |
|
| 42 | 1 | ); |
|
| 43 | |||
| 44 | 1 | if (($accelerate instanceof ResultInterface) and $accelerate[ '@metadata' ][ 'statusCode' ] === 200) { |
|
| 45 | 1 | $this->commandHandlerLogger?->log($this, sprintf('Bucket \'%s\' was successfully set to transfer accelerated mode', $bucketName)); |
|
| 46 | |||
| 47 | 1 | return true; |
|
| 48 | } |
||
| 49 | |||
| 50 | $this->commandHandlerLogger?->log($this, sprintf('Something went wrong during setting of bucket \'%s\' to transfer accelerated mode', $bucketName), 'warning'); |
||
| 51 | |||
| 52 | return false; |
||
| 53 | } catch (Exception $e) { |
||
| 54 | $this->commandHandlerLogger?->logExceptionAndReturnFalse($e); |
||
| 55 | |||
| 56 | throw $e; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param array $params |
||
| 62 | * |
||
| 63 | * @return bool |
||
| 64 | */ |
||
| 65 | 1 | public function validateParams(array $params = []): bool |
|
| 68 | } |
||
| 69 | } |
||
| 70 |