AccessPointArn.php 1.9 KB

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