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 | 50 | public function __construct() |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Main Methods |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Set the sitemap path. |
||
46 | * |
||
47 | * @param string $path |
||
48 | * |
||
49 | * @return self |
||
50 | */ |
||
51 | 30 | public function setPath($path) |
|
57 | |||
58 | /** |
||
59 | * Get the sitemap path. |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | 12 | public function getPath() |
|
67 | |||
68 | /** |
||
69 | * Get the sitemap's URLs. |
||
70 | * |
||
71 | * @return \Illuminate\Support\Collection |
||
72 | */ |
||
73 | 32 | 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 | * Get a URL instance by its loc. |
||
94 | * |
||
95 | * @param string $loc |
||
96 | * @param mixed|null $default |
||
97 | * |
||
98 | * @return \Arcanedev\LaravelSitemap\Entities\Url|null |
||
99 | */ |
||
100 | 2 | public function getUrl($loc, $default = null) |
|
104 | |||
105 | /** |
||
106 | * Add a sitemap URL to the collection. |
||
107 | * |
||
108 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Url $url |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | 42 | public function add(UrlContract $url) |
|
118 | |||
119 | /** |
||
120 | * Add many urls to the collection. |
||
121 | * |
||
122 | * @param array|\Illuminate\Support\Collection $urls |
||
123 | * |
||
124 | * @return self |
||
125 | */ |
||
126 | public function addMany($urls) |
||
132 | |||
133 | /** |
||
134 | * Create and Add a sitemap URL to the collection. |
||
135 | * |
||
136 | * @param string $loc |
||
137 | * @param callable $callback |
||
138 | * |
||
139 | * @return self |
||
140 | */ |
||
141 | 28 | public function create($loc, callable $callback) |
|
145 | |||
146 | /** |
||
147 | * Check if the url exists in the sitemap items. |
||
148 | * |
||
149 | * @param string $url |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | 4 | public function has($url) |
|
157 | |||
158 | /** |
||
159 | * Get the urls' count. |
||
160 | * |
||
161 | * @return int |
||
162 | */ |
||
163 | 30 | public function count() |
|
167 | |||
168 | /** |
||
169 | * Get the collection of items as a plain array. |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | 10 | public function toArray() |
|
177 | |||
178 | /** |
||
179 | * Get the sitemap and its urls as JSON. |
||
180 | * |
||
181 | * @param int $options |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | 2 | public function toJson($options = 0) |
|
189 | |||
190 | /** |
||
191 | * Convert the object into something JSON serializable. |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | 2 | public function jsonSerialize() |
|
199 | |||
200 | /** |
||
201 | * Check if the number of URLs is exceeded. |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | 20 | public function isExceeded() |
|
209 | |||
210 | /** |
||
211 | * Chunk the sitemap to multiple chunks. |
||
212 | * |
||
213 | * @return \Illuminate\Support\Collection |
||
214 | */ |
||
215 | public function chunk() |
||
225 | |||
226 | /* ----------------------------------------------------------------- |
||
227 | | Other Methods |
||
228 | | ----------------------------------------------------------------- |
||
229 | */ |
||
230 | |||
231 | 20 | protected function getMaxSize() |
|
235 | } |
||
236 |