1 | <?php namespace Arcanedev\LaravelSitemap\Entities; |
||
16 | class Url implements ArrayAccess, UrlContract |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Properties |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $loc; |
||
25 | |||
26 | /** @var string|null */ |
||
27 | protected $title; |
||
28 | |||
29 | /** @var \DateTimeInterface */ |
||
30 | protected $lastModDate; |
||
31 | |||
32 | /** @var string */ |
||
33 | protected $changeFrequency; |
||
34 | |||
35 | /** @var float */ |
||
36 | protected $priority; |
||
37 | |||
38 | /* ----------------------------------------------------------------- |
||
39 | | Constructor |
||
40 | | ----------------------------------------------------------------- |
||
41 | */ |
||
42 | |||
43 | /** |
||
44 | * Url constructor. |
||
45 | * |
||
46 | * @param string $loc |
||
47 | */ |
||
48 | 72 | public function __construct($loc) |
|
55 | |||
56 | /* ----------------------------------------------------------------- |
||
57 | | Getters & Setters |
||
58 | | ----------------------------------------------------------------- |
||
59 | */ |
||
60 | |||
61 | /** |
||
62 | * Get the url location. |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | 54 | public function getLoc() |
|
70 | |||
71 | /** |
||
72 | * Get the url location (alias). |
||
73 | * |
||
74 | * @see getLoc() |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | 14 | public function loc() |
|
82 | |||
83 | /** |
||
84 | * Set the url location. |
||
85 | * |
||
86 | * @param string $loc |
||
87 | * |
||
88 | * @return self |
||
89 | * |
||
90 | * @throws \Arcanedev\LaravelSitemap\Exceptions\SitemapException |
||
91 | */ |
||
92 | 72 | public function setLoc($loc) |
|
98 | |||
99 | /** |
||
100 | * Get the last modification date. |
||
101 | * |
||
102 | * @return \DateTimeInterface |
||
103 | */ |
||
104 | 30 | public function getLastMod() |
|
108 | |||
109 | /** |
||
110 | * Get the last modification date (alias). |
||
111 | * |
||
112 | * @see getLastMod() |
||
113 | * |
||
114 | * @return \DateTimeInterface |
||
115 | */ |
||
116 | 10 | public function lastMod() |
|
120 | |||
121 | /** |
||
122 | * Format the url last modification. |
||
123 | * |
||
124 | * @param string $format |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | 24 | public function formatLastMod($format = DateTime::ATOM) |
|
132 | |||
133 | /** |
||
134 | * Set the last modification date. |
||
135 | * |
||
136 | * @param string|\DateTimeInterface $lastModDate |
||
137 | * @param string $format |
||
138 | * |
||
139 | * @return self |
||
140 | */ |
||
141 | 72 | public function setLastMod($lastModDate, $format = 'Y-m-d H:i:s') |
|
149 | |||
150 | /** |
||
151 | * Get the change frequency. |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 28 | public function getChangeFreq() |
|
159 | |||
160 | /** |
||
161 | * Get the change frequency (alias). |
||
162 | * |
||
163 | * @see getChangeFreq() |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | 10 | public function changeFreq() |
|
171 | |||
172 | /** |
||
173 | * Set the change frequency. |
||
174 | * |
||
175 | * @param string $changeFreq |
||
176 | * |
||
177 | * @return self |
||
178 | */ |
||
179 | 72 | public function setChangeFreq($changeFreq) |
|
185 | |||
186 | /** |
||
187 | * Get the priority. |
||
188 | * |
||
189 | * @return float |
||
190 | */ |
||
191 | 28 | public function getPriority() |
|
195 | |||
196 | /** |
||
197 | * Get the priority (alias). |
||
198 | * |
||
199 | * @see getPriority() |
||
200 | * |
||
201 | * @return float |
||
202 | */ |
||
203 | 10 | public function priority() |
|
207 | |||
208 | /** |
||
209 | * Set the priority. |
||
210 | * |
||
211 | * @param float $priority |
||
212 | * |
||
213 | * @return self |
||
214 | * |
||
215 | * @throws \Arcanedev\LaravelSitemap\Exceptions\SitemapException |
||
216 | */ |
||
217 | 72 | public function setPriority($priority) |
|
223 | |||
224 | /** |
||
225 | * Get the title. |
||
226 | * |
||
227 | * @return string|null |
||
228 | */ |
||
229 | 24 | public function getTitle() |
|
233 | |||
234 | /** |
||
235 | * Get the title. |
||
236 | * |
||
237 | * @param string $title |
||
238 | * |
||
239 | * @return self |
||
240 | */ |
||
241 | 44 | public function setTitle($title) |
|
247 | |||
248 | /* ----------------------------------------------------------------- |
||
249 | | Main Methods |
||
250 | | ----------------------------------------------------------------- |
||
251 | */ |
||
252 | |||
253 | /** |
||
254 | * Create a sitemap url instance. |
||
255 | * |
||
256 | * @param string $loc |
||
257 | * |
||
258 | * @return \Arcanedev\LaravelSitemap\Entities\Url |
||
259 | */ |
||
260 | 56 | public static function make($loc) |
|
264 | |||
265 | /** |
||
266 | * Make a URL instance with attributes. |
||
267 | * |
||
268 | * @param array $attributes |
||
269 | * |
||
270 | * @return \Arcanedev\LaravelSitemap\Entities\Url |
||
271 | */ |
||
272 | 2 | public static function makeFromArray(array $attributes) |
|
280 | |||
281 | /** |
||
282 | * Get the collection of items as a plain array. |
||
283 | * |
||
284 | * @return array |
||
285 | */ |
||
286 | 14 | public function toArray() |
|
296 | |||
297 | /** |
||
298 | * Get the sitemap url as JSON. |
||
299 | * |
||
300 | * @param int $options |
||
301 | * |
||
302 | * @return string |
||
303 | */ |
||
304 | 2 | public function toJson($options = 0) |
|
308 | |||
309 | /** |
||
310 | * Convert the object into something JSON serializable. |
||
311 | * |
||
312 | * @return array |
||
313 | */ |
||
314 | 2 | public function jsonSerialize() |
|
318 | |||
319 | /* ----------------------------------------------------------------- |
||
320 | | Other Methods |
||
321 | | ----------------------------------------------------------------- |
||
322 | */ |
||
323 | |||
324 | /** |
||
325 | * Escape the given value. |
||
326 | * |
||
327 | * @param string $value |
||
328 | * |
||
329 | * @return string |
||
330 | */ |
||
331 | 56 | protected function escape($value) |
|
340 | |||
341 | /** |
||
342 | * Determine if the given attribute exists. |
||
343 | * |
||
344 | * @param mixed $offset |
||
345 | * |
||
346 | * @return bool |
||
347 | */ |
||
348 | 2 | public function offsetExists($offset) |
|
352 | |||
353 | /** |
||
354 | * Get the value for a given offset. |
||
355 | * |
||
356 | * @param mixed $offset |
||
357 | * |
||
358 | * @return mixed |
||
359 | */ |
||
360 | 2 | public function offsetGet($offset) |
|
364 | |||
365 | /** |
||
366 | * Set the value for a given offset. |
||
367 | * |
||
368 | * @param mixed $offset |
||
369 | * @param mixed $value |
||
370 | * |
||
371 | * @return void |
||
372 | */ |
||
373 | public function offsetSet($offset, $value) {} // Do nothing... |
||
374 | |||
375 | /** |
||
376 | * Unset the value for a given offset. |
||
377 | * |
||
378 | * @param mixed $offset |
||
379 | * |
||
380 | * @return void |
||
381 | */ |
||
382 | public function offsetUnset($offset) {} // Do nothing... |
||
383 | |||
384 | /** |
||
385 | * Check the loc value. |
||
386 | * |
||
387 | * @param string $loc |
||
388 | * |
||
389 | * @return string |
||
390 | * |
||
391 | * @throws \Arcanedev\LaravelSitemap\Exceptions\SitemapException |
||
392 | */ |
||
393 | 72 | protected function checkLoc($loc) |
|
400 | |||
401 | /** |
||
402 | * Check the priority value. |
||
403 | * |
||
404 | * @param float $priority |
||
405 | * |
||
406 | * @return float |
||
407 | * |
||
408 | * @throws \Arcanedev\LaravelSitemap\Exceptions\SitemapException |
||
409 | */ |
||
410 | 72 | protected function checkPriority($priority) |
|
422 | } |
||
423 |