1 | <?php |
||
14 | final class ResourceUri |
||
15 | { |
||
16 | |||
17 | const DEFAULT_PROTOCOL = 'file'; |
||
18 | |||
19 | /** |
||
20 | * @param $uri |
||
21 | * @return array |
||
22 | */ |
||
23 | private static function getNonEmptyParts($uri) |
||
31 | |||
32 | const PROTOCOL_SEPARATOR = '://'; |
||
33 | |||
34 | /** |
||
35 | * @param $parts |
||
36 | * @return bool |
||
37 | */ |
||
38 | 224 | private static function validateResourceParts($parts) |
|
42 | |||
43 | /** |
||
44 | * @param $protocol |
||
45 | * @param $resource |
||
46 | * @return self |
||
47 | */ |
||
48 | 20 | public static function fromProtocolAndResource($protocol, $resource) |
|
49 | { |
||
50 | 20 | return new self($protocol . self::PROTOCOL_SEPARATOR . $resource); |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param $uri |
||
55 | * @return bool |
||
56 | */ |
||
57 | 236 | public static function isValidUri($uri) |
|
75 | |||
76 | 148 | public static function fromString($uri) |
|
84 | |||
85 | 8 | public static function fromStringArray(array $uris) |
|
86 | { |
||
87 | 8 | $resourceUris = []; |
|
88 | |||
89 | 8 | foreach ($uris as $uri) { |
|
90 | 8 | $resourceUris[] = self::fromString($uri); |
|
91 | 6 | } |
|
92 | |||
93 | |||
94 | 4 | return $resourceUris; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * @var string |
||
99 | */ |
||
100 | private $uri; |
||
101 | |||
102 | /** |
||
103 | * @var string |
||
104 | */ |
||
105 | private $protocol; |
||
106 | |||
107 | /** |
||
108 | * @var string |
||
109 | */ |
||
110 | private $resource; |
||
111 | |||
112 | /** |
||
113 | * @param string $uri |
||
114 | */ |
||
115 | 180 | public function __construct($uri) |
|
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | 56 | public function getUri() |
|
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | 28 | public function getProtocol() |
|
144 | |||
145 | /** |
||
146 | * @return string |
||
147 | */ |
||
148 | 24 | public function getResource() |
|
152 | |||
153 | /** |
||
154 | * @return bool |
||
155 | */ |
||
156 | 24 | public function hasChainedResource() |
|
160 | |||
161 | /** |
||
162 | * @return self |
||
163 | */ |
||
164 | 16 | public function getChainedResource() |
|
168 | |||
169 | /** |
||
170 | * @param ResourceUri $other |
||
171 | * @return bool |
||
172 | */ |
||
173 | 8 | public function equals(ResourceUri $other) |
|
177 | |||
178 | 8 | public function chain($containerProtocol) |
|
182 | |||
183 | 12 | public function child($childRelativePath) |
|
187 | |||
188 | 12 | public function getPath() |
|
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | 44 | public function __toString() |
|
210 | } |
||
211 |