Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws\Arn;
3
 
4
use Aws\Arn\S3\AccessPointArn as S3AccessPointArn;
5
use Aws\Arn\ObjectLambdaAccessPointArn;
6
use Aws\Arn\S3\MultiRegionAccessPointArn;
7
use Aws\Arn\S3\OutpostsBucketArn;
8
use Aws\Arn\S3\RegionalBucketArn;
9
use Aws\Arn\S3\OutpostsAccessPointArn;
10
 
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
    /**
30
     * Parses a string and returns an instance of ArnInterface. Returns a
31
     * specific type of Arn object if it has a specific class representation
32
     * or a generic Arn object if not.
33
     *
34
     * @param $string
35
     * @return ArnInterface
36
     */
37
    public static function parse($string)
38
    {
39
        $data = Arn::parse($string);
40
        if ($data['service'] === 's3-object-lambda') {
41
            return new ObjectLambdaAccessPointArn($string);
42
        }
43
        $resource = self::explodeResourceComponent($data['resource']);
44
        if ($resource[0] === 'outpost') {
45
            if (isset($resource[2]) && $resource[2] === 'bucket') {
46
                return new OutpostsBucketArn($string);
47
            }
48
            if (isset($resource[2]) && $resource[2] === 'accesspoint') {
49
                return new OutpostsAccessPointArn($string);
50
            }
51
        }
52
        if (empty($data['region'])) {
53
            return new MultiRegionAccessPointArn($string);
54
        }
55
        if ($resource[0] === 'accesspoint') {
56
            if ($data['service'] === 's3') {
57
                return new S3AccessPointArn($string);
58
            }
59
            return new AccessPointArn($string);
60
        }
61
 
62
        return new Arn($data);
63
    }
64
 
65
    private static function explodeResourceComponent($resource)
66
    {
67
        return preg_split("/[\/:]/", $resource);
68
    }
69
}