1 | <?php |
||
47 | class ObjectUrl extends Url implements PathInterface |
||
48 | { |
||
49 | /** |
||
50 | * Object path |
||
51 | * |
||
52 | * @var LocalPath |
||
53 | */ |
||
54 | protected $_localPath = null; |
||
55 | |||
56 | /******************************************************************************* |
||
57 | * PUBLIC METHODS |
||
58 | *******************************************************************************/ |
||
59 | |||
60 | /** |
||
61 | * Object URL constructor |
||
62 | * |
||
63 | * @param string $url Object URL |
||
64 | * @param boolean $remote Accept remote URL (less strict date component checking) |
||
65 | * @throws InvalidArgumentException If remote URLs are not allowed and a remote URL is given |
||
66 | */ |
||
67 | 22 | public function __construct($url, $remote = false) |
|
90 | |||
91 | /** |
||
92 | * Return the object's creation date |
||
93 | * |
||
94 | * @return \DateTimeImmutable Object creation date |
||
95 | */ |
||
96 | 4 | public function getCreationDate() |
|
100 | |||
101 | /** |
||
102 | * Set the object's creation date |
||
103 | * |
||
104 | * @param \DateTimeImmutable $creationDate |
||
105 | * @return LocalPath New object path |
||
106 | */ |
||
107 | 1 | public function setCreationDate(\DateTimeImmutable $creationDate) |
|
112 | |||
113 | /** |
||
114 | * Return the object type |
||
115 | * |
||
116 | * @return Type Object type |
||
117 | */ |
||
118 | 4 | public function getType() |
|
122 | |||
123 | /** |
||
124 | * Set the object type |
||
125 | * |
||
126 | * @param Type $type Object type |
||
127 | * @return ObjectUrl New object URL |
||
128 | */ |
||
129 | 1 | public function setType(Type $type) |
|
134 | |||
135 | /** |
||
136 | * Return the object ID |
||
137 | * |
||
138 | * @return Id Object ID |
||
139 | */ |
||
140 | 6 | public function getId() |
|
144 | |||
145 | /** |
||
146 | * Set the object ID |
||
147 | * |
||
148 | * @param Id $id Object ID |
||
149 | * @return ObjectUrl New object URL |
||
150 | */ |
||
151 | 1 | public function setId(Id $id) |
|
156 | |||
157 | |||
158 | /** |
||
159 | * Return the object revision |
||
160 | * |
||
161 | * @return Revision Object revision |
||
162 | */ |
||
163 | 4 | public function getRevision() |
|
167 | |||
168 | /** |
||
169 | * Set the object revision |
||
170 | * |
||
171 | * @param Revision $revision Object revision |
||
172 | * @return ObjectUrl New object URL |
||
173 | */ |
||
174 | 1 | public function setRevision(Revision $revision) |
|
179 | |||
180 | /** |
||
181 | * Test if this URL matches all available parts of a given URL |
||
182 | * |
||
183 | * @param Url $url Comparison URL |
||
184 | * @return bool This URL matches all available parts of the given URL |
||
185 | */ |
||
186 | 3 | public function matches(Url $url) |
|
219 | |||
220 | /** |
||
221 | * Return the local object path |
||
222 | * |
||
223 | * @return LocalPath Local object path |
||
224 | */ |
||
225 | 1 | public function getLocalPath() |
|
226 | { |
||
227 | 1 | return $this->_localPath; |
|
228 | } |
||
229 | |||
230 | /** |
||
231 | * Return the repository URL part of this object URL |
||
232 | * |
||
233 | * @return string Repository URL |
||
234 | */ |
||
235 | 3 | public function getRepositoryUrl() |
|
236 | { |
||
237 | // If the object URL is absolute and local: Extract the repository URL |
||
238 | 3 | if ($this->isAbsoluteLocal()) { |
|
239 | 1 | $repositoryUrl = substr($this->getPath(), strlen((new Url(getenv('APPARAT_BASE_URL')))->getPath())); |
|
240 | |||
241 | // Else: If it's a relative URL: Extract the repository URL |
||
242 | 3 | } elseif (!$this->isAbsolute()) { |
|
243 | 2 | $repositoryUrl = $this->getPath(); |
|
244 | |||
245 | // Else: It must be a remote repository |
||
246 | 2 | } else { |
|
247 | $override = [ |
||
248 | 'object' => '', |
||
249 | 'query' => '', |
||
250 | 'fragment' => '', |
||
251 | ]; |
||
252 | $repositoryUrl = $this->_getUrl($override); |
||
253 | } |
||
254 | |||
255 | 3 | return $repositoryUrl; |
|
256 | } |
||
257 | |||
258 | /******************************************************************************* |
||
259 | * PRIVATE METHODS |
||
260 | *******************************************************************************/ |
||
261 | |||
262 | /** |
||
263 | * Return the a complete serialized object URL |
||
264 | * |
||
265 | * @param array $override Override components |
||
266 | * @return string Serialized URL |
||
267 | */ |
||
268 | 3 | protected function _getUrl(array &$override = []) |
|
282 | } |
||
283 |