| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Arn; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Arn\Exception\InvalidArnException; |
| 6 |
/** |
| 7 |
* @internal |
| 8 |
*/ |
| 9 |
class AccessPointArn extends Arn implements AccessPointArnInterface |
| 10 |
{ |
| 11 |
use ResourceTypeAndIdTrait; |
| 12 |
/** |
| 13 |
* AccessPointArn constructor |
| 14 |
* |
| 15 |
* @param $data |
| 16 |
*/ |
| 17 |
public function __construct($data) |
| 18 |
{ |
| 19 |
parent::__construct($data); |
| 20 |
static::validate($this->data); |
| 21 |
} |
| 22 |
public static function parse($string) |
| 23 |
{ |
| 24 |
$data = parent::parse($string); |
| 25 |
$data = self::parseResourceTypeAndId($data); |
| 26 |
$data['accesspoint_name'] = $data['resource_id']; |
| 27 |
return $data; |
| 28 |
} |
| 29 |
public function getAccesspointName() |
| 30 |
{ |
| 31 |
return $this->data['accesspoint_name']; |
| 32 |
} |
| 33 |
/** |
| 34 |
* Validation specific to AccessPointArn |
| 35 |
* |
| 36 |
* @param array $data |
| 37 |
*/ |
| 38 |
protected static function validate(array $data) |
| 39 |
{ |
| 40 |
self::validateRegion($data, 'access point ARN'); |
| 41 |
self::validateAccountId($data, 'access point ARN'); |
| 42 |
if ($data['resource_type'] !== 'accesspoint') { |
| 43 |
throw new InvalidArnException("The 6th component of an access point ARN" . " represents the resource type and must be 'accesspoint'."); |
| 44 |
} |
| 45 |
if (empty($data['resource_id'])) { |
| 46 |
throw new InvalidArnException("The 7th component of an access point ARN" . " represents the resource ID and must not be empty."); |
| 47 |
} |
| 48 |
if (\strpos($data['resource_id'], ':') !== \false) { |
| 49 |
throw new InvalidArnException("The resource ID component of an access" . " point ARN must not contain additional components" . " (delimited by ':')."); |
| 50 |
} |
| 51 |
if (!self::isValidHostLabel($data['resource_id'])) { |
| 52 |
throw new InvalidArnException("The resource ID in an access point ARN" . " must be a valid host label value."); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|