1 | <?php namespace Arcanedev\LaravelSitemap; |
||
15 | class SitemapManager implements SitemapManagerContract |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Properties |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** @var \Illuminate\Support\Collection */ |
||
23 | protected $sitemaps; |
||
24 | |||
25 | /** @var string */ |
||
26 | protected $format = 'xml'; |
||
27 | |||
28 | /* ----------------------------------------------------------------- |
||
29 | | Constructor |
||
30 | | ----------------------------------------------------------------- |
||
31 | */ |
||
32 | |||
33 | /** |
||
34 | * SitemapManager constructor. |
||
35 | */ |
||
36 | 76 | public function __construct() |
|
40 | |||
41 | /* ----------------------------------------------------------------- |
||
42 | | Getters & Setters |
||
43 | | ----------------------------------------------------------------- |
||
44 | */ |
||
45 | |||
46 | /** |
||
47 | * Set the format. |
||
48 | * |
||
49 | * @param string $format |
||
50 | * |
||
51 | * @return self |
||
52 | */ |
||
53 | 20 | public function format($format) |
|
59 | |||
60 | /* ----------------------------------------------------------------- |
||
61 | | Main Methods |
||
62 | | ----------------------------------------------------------------- |
||
63 | */ |
||
64 | |||
65 | /** |
||
66 | * Create and add a sitemap to the collection. |
||
67 | * |
||
68 | * @param string $name |
||
69 | * @param callable $callback |
||
70 | * |
||
71 | * @return self |
||
72 | */ |
||
73 | 4 | public function create($name, callable $callback) |
|
77 | |||
78 | /** |
||
79 | * Add a sitemap to the collection. |
||
80 | * |
||
81 | * @param string $name |
||
82 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap $sitemap |
||
83 | * |
||
84 | * @return self |
||
85 | */ |
||
86 | 64 | public function add($name, SitemapContract $sitemap) |
|
92 | |||
93 | /** |
||
94 | * Get the sitemaps collection. |
||
95 | * |
||
96 | * @return \Illuminate\Support\Collection |
||
97 | */ |
||
98 | 20 | public function all() |
|
102 | |||
103 | /** |
||
104 | * Get a sitemap instance. |
||
105 | * |
||
106 | * @param string $name |
||
107 | * @param mixed|null $default |
||
108 | * |
||
109 | * @return mixed |
||
110 | */ |
||
111 | 8 | public function get($name, $default = null) |
|
115 | |||
116 | /** |
||
117 | * Check if a sitemap exists. |
||
118 | * |
||
119 | * @param string $name |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | 8 | public function has($name) |
|
138 | |||
139 | /** |
||
140 | * Remove a sitemap from the collection by key. |
||
141 | * |
||
142 | * @param string|array $names |
||
143 | * |
||
144 | * @return self |
||
145 | */ |
||
146 | 4 | public function forget($names) |
|
152 | |||
153 | /** |
||
154 | * Get the sitemaps count. |
||
155 | * |
||
156 | * @return int |
||
157 | */ |
||
158 | 16 | public function count() |
|
162 | |||
163 | /** |
||
164 | * Render the sitemaps. |
||
165 | * |
||
166 | * @param string $name |
||
167 | * |
||
168 | * @throws \Throwable |
||
169 | * |
||
170 | * @return string|null |
||
171 | */ |
||
172 | 44 | public function render($name = null) |
|
176 | |||
177 | /** |
||
178 | * Save the sitemaps. |
||
179 | * |
||
180 | * @param string $path |
||
181 | * @param string|null $name |
||
182 | * |
||
183 | * @throws \Throwable |
||
184 | * |
||
185 | * @return self |
||
186 | */ |
||
187 | 16 | public function save($path, $name = null) |
|
202 | |||
203 | /** |
||
204 | * Render the Http response. |
||
205 | * |
||
206 | * @param string $name |
||
207 | * @param int $status |
||
208 | * @param array $headers |
||
209 | * |
||
210 | * @throws \Throwable |
||
211 | * |
||
212 | * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response |
||
213 | */ |
||
214 | 4 | public function respond($name = null, $status = 200, array $headers = []) |
|
218 | |||
219 | /** |
||
220 | * Get the collection of items as a plain array. |
||
221 | * |
||
222 | * @return array |
||
223 | */ |
||
224 | 8 | public function toArray() |
|
228 | |||
229 | /** |
||
230 | * Get the collection of sitemaps as JSON. |
||
231 | * |
||
232 | * @param int $options |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | 4 | public function toJson($options = 0) |
|
240 | |||
241 | /** |
||
242 | * Convert the object into something JSON serializable. |
||
243 | * |
||
244 | * @return array |
||
245 | */ |
||
246 | 4 | public function jsonSerialize() |
|
250 | |||
251 | /** |
||
252 | * Save multiple sitemap. |
||
253 | * |
||
254 | * @param string $path |
||
255 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap $sitemap |
||
256 | * |
||
257 | * @throws \Throwable |
||
258 | */ |
||
259 | 4 | private function saveMultiple($path, $sitemap) |
|
271 | |||
272 | /** |
||
273 | * Get the response header. |
||
274 | * |
||
275 | * @return array |
||
276 | */ |
||
277 | 4 | protected function getResponseHeaders() |
|
285 | } |
||
286 |