1 | <?php |
||
17 | class Sitemap implements SitemapContract |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Properties |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** @var string|null */ |
||
25 | protected $path; |
||
26 | |||
27 | /** @var \Illuminate\Support\Collection */ |
||
28 | protected $urls; |
||
29 | |||
30 | /* ----------------------------------------------------------------- |
||
31 | | Constructor |
||
32 | | ----------------------------------------------------------------- |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * Sitemap constructor. |
||
37 | */ |
||
38 | 168 | public function __construct() |
|
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Getters & Setters |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Set the sitemap path. |
||
50 | * |
||
51 | * @param string $path |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | 96 | public function setPath(string $path) |
|
61 | |||
62 | /** |
||
63 | * Get the sitemap path. |
||
64 | * |
||
65 | * @return string|null |
||
66 | */ |
||
67 | 42 | public function getPath(): ?string |
|
71 | |||
72 | /** |
||
73 | * Get the sitemap's URLs. |
||
74 | * |
||
75 | * @return \Illuminate\Support\Collection |
||
76 | */ |
||
77 | 108 | public function getUrls(): Collection |
|
81 | |||
82 | /** |
||
83 | * Set the URLs Collection. |
||
84 | * |
||
85 | * @param \Illuminate\Support\Collection $urls |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | 18 | public function setUrls(Collection $urls) |
|
95 | |||
96 | /* ----------------------------------------------------------------- |
||
97 | | Main Methods |
||
98 | | ----------------------------------------------------------------- |
||
99 | */ |
||
100 | |||
101 | /** |
||
102 | * Make a sitemap instance. |
||
103 | * |
||
104 | * @return $this |
||
105 | */ |
||
106 | 12 | public static function make() |
|
110 | |||
111 | /** |
||
112 | * Get a URL instance by its loc. |
||
113 | * |
||
114 | * @param string $loc |
||
115 | * @param mixed|null $default |
||
116 | * |
||
117 | * @return \Arcanedev\LaravelSitemap\Entities\Url|null |
||
118 | */ |
||
119 | 6 | public function getUrl(string $loc, $default = null) |
|
123 | |||
124 | /** |
||
125 | * Add a sitemap URL to the collection. |
||
126 | * |
||
127 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Url $url |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | 144 | public function add(UrlContract $url) |
|
137 | |||
138 | /** |
||
139 | * Add many urls to the collection. |
||
140 | * |
||
141 | * @param iterable|mixed $urls |
||
142 | * |
||
143 | * @return $this |
||
144 | */ |
||
145 | 6 | public function addMany(iterable $urls) |
|
153 | |||
154 | /** |
||
155 | * Create and Add a sitemap URL to the collection. |
||
156 | * |
||
157 | * @param string $loc |
||
158 | * @param callable $callback |
||
159 | * |
||
160 | * @return $this |
||
161 | */ |
||
162 | 90 | public function create(string $loc, callable $callback) |
|
166 | |||
167 | /** |
||
168 | * Check if the url exists in the sitemap items. |
||
169 | * |
||
170 | * @param string $url |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | 12 | public function has(string $url): bool |
|
178 | |||
179 | /** |
||
180 | * Get the urls' count. |
||
181 | * |
||
182 | * @return int |
||
183 | */ |
||
184 | 108 | public function count(): int |
|
188 | |||
189 | /** |
||
190 | * Get the collection of items as a plain array. |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | 36 | public function toArray(): array |
|
198 | |||
199 | /** |
||
200 | * Get the sitemap and its urls as JSON. |
||
201 | * |
||
202 | * @param int $options |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | 6 | public function toJson($options = 0): string |
|
210 | |||
211 | /** |
||
212 | * Convert the object into something JSON serializable. |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | 6 | public function jsonSerialize(): array |
|
220 | |||
221 | /** |
||
222 | * Check if the number of URLs is exceeded. |
||
223 | * |
||
224 | * @return bool |
||
225 | */ |
||
226 | 66 | public function isExceeded(): bool |
|
230 | |||
231 | /** |
||
232 | * Chunk the sitemap to multiple chunks if the size is exceeded. |
||
233 | * |
||
234 | * @return \Illuminate\Support\Collection |
||
235 | */ |
||
236 | 12 | public function chunk(): Collection |
|
250 | |||
251 | /* ----------------------------------------------------------------- |
||
252 | | Other Methods |
||
253 | | ----------------------------------------------------------------- |
||
254 | */ |
||
255 | |||
256 | /** |
||
257 | * Get the max size. |
||
258 | * |
||
259 | * @return int |
||
260 | */ |
||
261 | 66 | protected function getMaxSize(): int |
|
265 | } |
||
266 |