1 | <?php |
||
19 | class SitemapManager implements SitemapManagerContract |
||
20 | { |
||
21 | /* ----------------------------------------------------------------- |
||
22 | | Properties |
||
23 | | ----------------------------------------------------------------- |
||
24 | */ |
||
25 | |||
26 | /** @var \Illuminate\Support\Collection */ |
||
27 | protected $sitemaps; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $format = 'xml'; |
||
31 | |||
32 | /* ----------------------------------------------------------------- |
||
33 | | Constructor |
||
34 | | ----------------------------------------------------------------- |
||
35 | */ |
||
36 | |||
37 | /** |
||
38 | * SitemapManager constructor. |
||
39 | */ |
||
40 | 114 | public function __construct() |
|
44 | |||
45 | /* ----------------------------------------------------------------- |
||
46 | | Getters & Setters |
||
47 | | ----------------------------------------------------------------- |
||
48 | */ |
||
49 | |||
50 | /** |
||
51 | * Set the format. |
||
52 | * |
||
53 | * @param string $format |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | 30 | public function format($format) |
|
63 | |||
64 | /* ----------------------------------------------------------------- |
||
65 | | Main Methods |
||
66 | | ----------------------------------------------------------------- |
||
67 | */ |
||
68 | |||
69 | /** |
||
70 | * Create and add a sitemap to the collection. |
||
71 | * |
||
72 | * @param string $name |
||
73 | * @param callable $callback |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | 6 | public function create(string $name, callable $callback) |
|
81 | |||
82 | /** |
||
83 | * Add a sitemap to the collection. |
||
84 | * |
||
85 | * @param string $name |
||
86 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap $sitemap |
||
87 | * |
||
88 | * @return $this |
||
89 | */ |
||
90 | 96 | public function add(string $name, SitemapContract $sitemap) |
|
96 | |||
97 | /** |
||
98 | * Get the sitemaps collection. |
||
99 | * |
||
100 | * @return \Illuminate\Support\Collection |
||
101 | */ |
||
102 | 30 | public function all(): Collection |
|
106 | |||
107 | /** |
||
108 | * Get a sitemap instance. |
||
109 | * |
||
110 | * @param string $name |
||
111 | * @param mixed|null $default |
||
112 | * |
||
113 | * @return \Arcanedev\LaravelSitemap\Entities\Sitemap|mixed|null |
||
114 | */ |
||
115 | 12 | public function get(string $name, $default = null) |
|
119 | |||
120 | /** |
||
121 | * Check if a sitemap exists. |
||
122 | * |
||
123 | * @param string $name |
||
124 | * |
||
125 | * @return bool |
||
126 | */ |
||
127 | 12 | public function has(string $name): bool |
|
142 | |||
143 | /** |
||
144 | * Remove a sitemap from the collection by key. |
||
145 | * |
||
146 | * @param string|array $names |
||
147 | * |
||
148 | * @return $this |
||
149 | */ |
||
150 | 6 | public function forget($names) |
|
156 | |||
157 | /** |
||
158 | * Get the sitemaps count. |
||
159 | * |
||
160 | * @return int |
||
161 | */ |
||
162 | 24 | public function count(): int |
|
166 | |||
167 | /** |
||
168 | * Render the sitemaps. |
||
169 | * |
||
170 | * @param string $name |
||
171 | * |
||
172 | * @throws \Throwable |
||
173 | * |
||
174 | * @return string|null |
||
175 | */ |
||
176 | 66 | public function render(string $name = null): ?string |
|
180 | |||
181 | /** |
||
182 | * Save the sitemaps. |
||
183 | * |
||
184 | * @param string $path |
||
185 | * @param string|null $name |
||
186 | * |
||
187 | * @throws \Throwable |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | 24 | public function save(string $path, string $name = null) |
|
206 | |||
207 | /** |
||
208 | * Render the Http response. |
||
209 | * |
||
210 | * @param string $name |
||
211 | * @param int $status |
||
212 | * @param array $headers |
||
213 | * |
||
214 | * @throws \Throwable |
||
215 | * |
||
216 | * @return \Illuminate\Http\Response|mixed |
||
217 | */ |
||
218 | 6 | public function respond(string $name = null, int $status = Response::HTTP_OK, array $headers = []) |
|
222 | |||
223 | /** |
||
224 | * Get the collection of items as a plain array. |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | 12 | public function toArray(): array |
|
232 | |||
233 | /** |
||
234 | * Get the collection of sitemaps as JSON. |
||
235 | * |
||
236 | * @param int $options |
||
237 | * |
||
238 | * @return string |
||
239 | */ |
||
240 | 6 | public function toJson($options = 0): string |
|
244 | |||
245 | /** |
||
246 | * Convert the object into something JSON serializable. |
||
247 | * |
||
248 | * @return array |
||
249 | */ |
||
250 | 6 | public function jsonSerialize(): array |
|
254 | |||
255 | /** |
||
256 | * Save multiple sitemap. |
||
257 | * |
||
258 | * @param string $path |
||
259 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap $sitemap |
||
260 | * |
||
261 | * @throws \Throwable |
||
262 | */ |
||
263 | 6 | private function saveMultiple(string $path, SitemapContract $sitemap) |
|
275 | |||
276 | /** |
||
277 | * Get the response header. |
||
278 | * |
||
279 | * @return array |
||
280 | */ |
||
281 | 6 | protected function getResponseHeaders(): array |
|
289 | } |
||
290 |