1 | <?php namespace Arcanedev\LaravelSitemap\Entities; |
||
13 | class Sitemap implements SitemapContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** @var string|null */ |
||
21 | protected $path; |
||
22 | |||
23 | /** @var \Illuminate\Support\Collection */ |
||
24 | protected $urls; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Constructor |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** |
||
32 | * Sitemap constructor. |
||
33 | */ |
||
34 | 56 | public function __construct() |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Getters & Setters |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Set the sitemap path. |
||
46 | * |
||
47 | * @param string $path |
||
48 | * |
||
49 | * @return self |
||
50 | */ |
||
51 | 32 | public function setPath($path) |
|
57 | |||
58 | /** |
||
59 | * Get the sitemap path. |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | 14 | public function getPath() |
|
67 | |||
68 | /** |
||
69 | * Get the sitemap's URLs. |
||
70 | * |
||
71 | * @return \Illuminate\Support\Collection |
||
72 | */ |
||
73 | 36 | public function getUrls() |
|
77 | |||
78 | /** |
||
79 | * Set the URLs Collection. |
||
80 | * |
||
81 | * @param \Illuminate\Support\Collection $urls |
||
82 | * |
||
83 | * @return self |
||
84 | */ |
||
85 | 6 | public function setUrls(Collection $urls) |
|
91 | |||
92 | /* ----------------------------------------------------------------- |
||
93 | | Main Methods |
||
94 | | ----------------------------------------------------------------- |
||
95 | */ |
||
96 | |||
97 | /** |
||
98 | * Make a sitemap instance. |
||
99 | * |
||
100 | * @return self |
||
101 | */ |
||
102 | 4 | public static function make() |
|
106 | |||
107 | /** |
||
108 | * Get a URL instance by its loc. |
||
109 | * |
||
110 | * @param string $loc |
||
111 | * @param mixed|null $default |
||
112 | * |
||
113 | * @return \Arcanedev\LaravelSitemap\Entities\Url|null |
||
114 | */ |
||
115 | 2 | public function getUrl($loc, $default = null) |
|
119 | |||
120 | /** |
||
121 | * Add a sitemap URL to the collection. |
||
122 | * |
||
123 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Url $url |
||
124 | * |
||
125 | * @return $this |
||
126 | */ |
||
127 | 48 | public function add(UrlContract $url) |
|
133 | |||
134 | /** |
||
135 | * Add many urls to the collection. |
||
136 | * |
||
137 | * @param array|\Illuminate\Support\Collection $urls |
||
138 | * |
||
139 | * @return self |
||
140 | */ |
||
141 | 2 | public function addMany($urls) |
|
149 | |||
150 | /** |
||
151 | * Create and Add a sitemap URL to the collection. |
||
152 | * |
||
153 | * @param string $loc |
||
154 | * @param callable $callback |
||
155 | * |
||
156 | * @return self |
||
157 | */ |
||
158 | 30 | public function create($loc, callable $callback) |
|
162 | |||
163 | /** |
||
164 | * Check if the url exists in the sitemap items. |
||
165 | * |
||
166 | * @param string $url |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 4 | public function has($url) |
|
174 | |||
175 | /** |
||
176 | * Get the urls' count. |
||
177 | * |
||
178 | * @return int |
||
179 | */ |
||
180 | 36 | public function count() |
|
184 | |||
185 | /** |
||
186 | * Get the collection of items as a plain array. |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | 12 | public function toArray() |
|
194 | |||
195 | /** |
||
196 | * Get the sitemap and its urls as JSON. |
||
197 | * |
||
198 | * @param int $options |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | 2 | public function toJson($options = 0) |
|
206 | |||
207 | /** |
||
208 | * Convert the object into something JSON serializable. |
||
209 | * |
||
210 | * @return array |
||
211 | */ |
||
212 | 2 | public function jsonSerialize() |
|
216 | |||
217 | /** |
||
218 | * Check if the number of URLs is exceeded. |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | 22 | public function isExceeded() |
|
226 | |||
227 | /** |
||
228 | * Chunk the sitemap to multiple chunks if the size is exceeded. |
||
229 | * |
||
230 | * @return \Illuminate\Support\Collection |
||
231 | */ |
||
232 | public function chunk() |
||
242 | |||
243 | /* ----------------------------------------------------------------- |
||
244 | | Other Methods |
||
245 | | ----------------------------------------------------------------- |
||
246 | */ |
||
247 | |||
248 | /** |
||
249 | * Get the max size. |
||
250 | * |
||
251 | * @return int |
||
252 | */ |
||
253 | 22 | protected function getMaxSize() |
|
257 | } |
||
258 |