| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Arn; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Arn\S3\AccessPointArn as S3AccessPointArn; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\Arn\ObjectLambdaAccessPointArn; |
| 7 |
use Dudlewebs\WPMCS\s3\Aws\Arn\S3\MultiRegionAccessPointArn; |
| 8 |
use Dudlewebs\WPMCS\s3\Aws\Arn\S3\OutpostsBucketArn; |
| 9 |
use Dudlewebs\WPMCS\s3\Aws\Arn\S3\RegionalBucketArn; |
| 10 |
use Dudlewebs\WPMCS\s3\Aws\Arn\S3\OutpostsAccessPointArn; |
| 11 |
/** |
| 12 |
* This class provides functionality to parse ARN strings and return a |
| 13 |
* corresponding ARN object. ARN-parsing logic may be subject to change in the |
| 14 |
* future, so this should not be relied upon for external customer usage. |
| 15 |
* |
| 16 |
* @internal |
| 17 |
*/ |
| 18 |
class ArnParser |
| 19 |
{ |
| 20 |
/** |
| 21 |
* @param $string |
| 22 |
* @return bool |
| 23 |
*/ |
| 24 |
public static function isArn($string) |
| 25 |
{ |
| 26 |
return $string !== null && \strpos($string, 'arn:') === 0; |
| 27 |
} |
| 28 |
/** |
| 29 |
* Parses a string and returns an instance of ArnInterface. Returns a |
| 30 |
* specific type of Arn object if it has a specific class representation |
| 31 |
* or a generic Arn object if not. |
| 32 |
* |
| 33 |
* @param $string |
| 34 |
* @return ArnInterface |
| 35 |
*/ |
| 36 |
public static function parse($string) |
| 37 |
{ |
| 38 |
$data = Arn::parse($string); |
| 39 |
if ($data['service'] === 's3-object-lambda') { |
| 40 |
return new ObjectLambdaAccessPointArn($string); |
| 41 |
} |
| 42 |
$resource = self::explodeResourceComponent($data['resource']); |
| 43 |
if ($resource[0] === 'outpost') { |
| 44 |
if (isset($resource[2]) && $resource[2] === 'bucket') { |
| 45 |
return new OutpostsBucketArn($string); |
| 46 |
} |
| 47 |
if (isset($resource[2]) && $resource[2] === 'accesspoint') { |
| 48 |
return new OutpostsAccessPointArn($string); |
| 49 |
} |
| 50 |
} |
| 51 |
if (empty($data['region'])) { |
| 52 |
return new MultiRegionAccessPointArn($string); |
| 53 |
} |
| 54 |
if ($resource[0] === 'accesspoint') { |
| 55 |
if ($data['service'] === 's3') { |
| 56 |
return new S3AccessPointArn($string); |
| 57 |
} |
| 58 |
return new AccessPointArn($string); |
| 59 |
} |
| 60 |
return new Arn($data); |
| 61 |
} |
| 62 |
private static function explodeResourceComponent($resource) |
| 63 |
{ |
| 64 |
return \preg_split("/[\\/:]/", $resource); |
| 65 |
} |
| 66 |
} |
| 67 |
|