OutpostsBucketArn.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Aws\Arn\S3;
  3. use Aws\Arn\Arn;
  4. use Aws\Arn\Exception\InvalidArnException;
  5. use Aws\Arn\ResourceTypeAndIdTrait;
  6. /**
  7. * This class represents an S3 Outposts bucket ARN, which is in the
  8. * following format:
  9. *
  10. * @internal
  11. */
  12. class OutpostsBucketArn extends Arn implements
  13. BucketArnInterface,
  14. 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])
  42. ? $resourceData[0]
  43. : null;
  44. $data['bucket_label'] = isset($resourceData[1])
  45. ? $resourceData[1]
  46. : null;
  47. $data['bucket_name'] = isset($resourceData[2])
  48. ? $resourceData[2]
  49. : null;
  50. return $data;
  51. }
  52. /**
  53. *
  54. * @param array $data
  55. */
  56. public static function validate(array $data)
  57. {
  58. Arn::validate($data);
  59. if (($data['service'] !== 's3-outposts')) {
  60. throw new InvalidArnException("The 3rd component of an S3 Outposts"
  61. . " bucket ARN represents the service and must be 's3-outposts'.");
  62. }
  63. self::validateRegion($data, 'S3 Outposts bucket ARN');
  64. self::validateAccountId($data, 'S3 Outposts bucket ARN');
  65. if (($data['resource_type'] !== 'outpost')) {
  66. throw new InvalidArnException("The 6th component of an S3 Outposts"
  67. . " bucket ARN represents the resource type and must be"
  68. . " 'outpost'.");
  69. }
  70. if (!self::isValidHostLabel($data['outpost_id'])) {
  71. throw new InvalidArnException("The 7th component of an S3 Outposts"
  72. . " bucket ARN is required, represents the outpost ID, and"
  73. . " must be a valid host label.");
  74. }
  75. if ($data['bucket_label'] !== 'bucket') {
  76. throw new InvalidArnException("The 8th component of an S3 Outposts"
  77. . " bucket ARN must be 'bucket'");
  78. }
  79. if (empty($data['bucket_name'])) {
  80. throw new InvalidArnException("The 9th component of an S3 Outposts"
  81. . " bucket ARN represents the bucket name and must not be empty.");
  82. }
  83. }
  84. }