| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Arn\S3; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Arn\Arn; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\Arn\Exception\InvalidArnException; |
| 7 |
use Dudlewebs\WPMCS\s3\Aws\Arn\ResourceTypeAndIdTrait; |
| 8 |
/** |
| 9 |
* This class represents an S3 Outposts bucket ARN, which is in the |
| 10 |
* following format: |
| 11 |
* |
| 12 |
* @internal |
| 13 |
*/ |
| 14 |
class OutpostsBucketArn extends Arn implements BucketArnInterface, OutpostsArnInterface |
| 15 |
{ |
| 16 |
use ResourceTypeAndIdTrait; |
| 17 |
/** |
| 18 |
* Parses a string into an associative array of components that represent |
| 19 |
* a OutpostsBucketArn |
| 20 |
* |
| 21 |
* @param $string |
| 22 |
* @return array |
| 23 |
*/ |
| 24 |
public static function parse($string) |
| 25 |
{ |
| 26 |
$data = parent::parse($string); |
| 27 |
$data = self::parseResourceTypeAndId($data); |
| 28 |
return self::parseOutpostData($data); |
| 29 |
} |
| 30 |
public function getBucketName() |
| 31 |
{ |
| 32 |
return $this->data['bucket_name']; |
| 33 |
} |
| 34 |
public function getOutpostId() |
| 35 |
{ |
| 36 |
return $this->data['outpost_id']; |
| 37 |
} |
| 38 |
private static function parseOutpostData(array $data) |
| 39 |
{ |
| 40 |
$resourceData = \preg_split("/[\\/:]/", $data['resource_id'], 3); |
| 41 |
$data['outpost_id'] = isset($resourceData[0]) ? $resourceData[0] : null; |
| 42 |
$data['bucket_label'] = isset($resourceData[1]) ? $resourceData[1] : null; |
| 43 |
$data['bucket_name'] = isset($resourceData[2]) ? $resourceData[2] : null; |
| 44 |
return $data; |
| 45 |
} |
| 46 |
/** |
| 47 |
* |
| 48 |
* @param array $data |
| 49 |
*/ |
| 50 |
public static function validate(array $data) |
| 51 |
{ |
| 52 |
Arn::validate($data); |
| 53 |
if ($data['service'] !== 's3-outposts') { |
| 54 |
throw new InvalidArnException("The 3rd component of an S3 Outposts" . " bucket ARN represents the service and must be 's3-outposts'."); |
| 55 |
} |
| 56 |
self::validateRegion($data, 'S3 Outposts bucket ARN'); |
| 57 |
self::validateAccountId($data, 'S3 Outposts bucket ARN'); |
| 58 |
if ($data['resource_type'] !== 'outpost') { |
| 59 |
throw new InvalidArnException("The 6th component of an S3 Outposts" . " bucket ARN represents the resource type and must be" . " 'outpost'."); |
| 60 |
} |
| 61 |
if (!self::isValidHostLabel($data['outpost_id'])) { |
| 62 |
throw new InvalidArnException("The 7th component of an S3 Outposts" . " bucket ARN is required, represents the outpost ID, and" . " must be a valid host label."); |
| 63 |
} |
| 64 |
if ($data['bucket_label'] !== 'bucket') { |
| 65 |
throw new InvalidArnException("The 8th component of an S3 Outposts" . " bucket ARN must be 'bucket'"); |
| 66 |
} |
| 67 |
if (empty($data['bucket_name'])) { |
| 68 |
throw new InvalidArnException("The 9th component of an S3 Outposts" . " bucket ARN represents the bucket name and must not be empty."); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|