PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Arn / ArnParser.php

ArnParser.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/Arn/ArnParser.php

67 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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