1 | <?php namespace Arcanedev\LaravelSitemap; |
||
14 | class SitemapManager implements SitemapManagerContract |
||
15 | { |
||
16 | /* ----------------------------------------------------------------- |
||
17 | | Properties |
||
18 | | ----------------------------------------------------------------- |
||
19 | */ |
||
20 | |||
21 | /** @var \Illuminate\Support\Collection */ |
||
22 | protected $sitemaps; |
||
23 | |||
24 | /** @var string */ |
||
25 | protected $format = 'xml'; |
||
26 | |||
27 | /* ----------------------------------------------------------------- |
||
28 | | Constructor |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | /** |
||
33 | * SitemapManager constructor. |
||
34 | */ |
||
35 | 38 | public function __construct() |
|
39 | |||
40 | /* ----------------------------------------------------------------- |
||
41 | | Getters & Setters |
||
42 | | ----------------------------------------------------------------- |
||
43 | */ |
||
44 | |||
45 | /** |
||
46 | * Set the format. |
||
47 | * |
||
48 | * @param string $format |
||
49 | * |
||
50 | * @return self |
||
51 | */ |
||
52 | 10 | public function format($format) |
|
58 | |||
59 | /* ----------------------------------------------------------------- |
||
60 | | Main Methods |
||
61 | | ----------------------------------------------------------------- |
||
62 | */ |
||
63 | |||
64 | /** |
||
65 | * Create and add a sitemap to the collection. |
||
66 | * |
||
67 | * @param string $name |
||
68 | * @param callable $callback |
||
69 | * |
||
70 | * @return self |
||
71 | */ |
||
72 | 2 | public function create($name, callable $callback) |
|
76 | |||
77 | /** |
||
78 | * Add a sitemap to the collection. |
||
79 | * |
||
80 | * @param string $name |
||
81 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap $sitemap |
||
82 | * |
||
83 | * @return self |
||
84 | */ |
||
85 | 32 | public function add($name, SitemapContract $sitemap) |
|
91 | |||
92 | /** |
||
93 | * Get the sitemaps collection. |
||
94 | * |
||
95 | * @return \Illuminate\Support\Collection |
||
96 | */ |
||
97 | 10 | public function all() |
|
101 | |||
102 | /** |
||
103 | * Get a sitemap instance. |
||
104 | * |
||
105 | * @param string $name |
||
106 | * @param mixed|null $default |
||
107 | * |
||
108 | * @return mixed |
||
109 | */ |
||
110 | 4 | public function get($name, $default = null) |
|
114 | |||
115 | /** |
||
116 | * Check if a sitemap exists. |
||
117 | * |
||
118 | * @param string $name |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | 2 | public function has($name) |
|
126 | |||
127 | /** |
||
128 | * Remove a sitemap from the collection by key. |
||
129 | * |
||
130 | * @param string|array $names |
||
131 | * |
||
132 | * @return self |
||
133 | */ |
||
134 | 2 | public function forget($names) |
|
140 | |||
141 | /** |
||
142 | * Get the sitemaps count. |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | 8 | public function count() |
|
150 | |||
151 | /** |
||
152 | * Render the sitemaps. |
||
153 | * |
||
154 | * @param string $name |
||
155 | * |
||
156 | * @return string|null |
||
157 | */ |
||
158 | 22 | public function render($name = null) |
|
162 | |||
163 | /** |
||
164 | * Save the sitemaps. |
||
165 | * |
||
166 | * @param string $path |
||
167 | * @param string|null $name |
||
168 | * |
||
169 | * @return self |
||
170 | */ |
||
171 | 8 | public function save($path, $name = null) |
|
186 | |||
187 | /** |
||
188 | * Render the Http response. |
||
189 | * |
||
190 | * @param string $name |
||
191 | * @param int $status |
||
192 | * @param array $headers |
||
193 | * |
||
194 | * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response |
||
195 | */ |
||
196 | 2 | public function respond($name = null, $status = 200, array $headers = []) |
|
200 | |||
201 | /** |
||
202 | * Get the collection of items as a plain array. |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | 4 | public function toArray() |
|
210 | |||
211 | /** |
||
212 | * Get the collection of sitemaps as JSON. |
||
213 | * |
||
214 | * @param int $options |
||
215 | * |
||
216 | * @return string |
||
217 | */ |
||
218 | 2 | public function toJson($options = 0) |
|
222 | |||
223 | /** |
||
224 | * Convert the object into something JSON serializable. |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | 2 | public function jsonSerialize() |
|
232 | |||
233 | /** |
||
234 | * Save multiple sitemap. |
||
235 | * |
||
236 | * @param string $path |
||
237 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap $sitemap |
||
238 | */ |
||
239 | 2 | private function saveMultiple($path, $sitemap) |
|
251 | |||
252 | /** |
||
253 | * Get the response header. |
||
254 | * |
||
255 | * @return array |
||
256 | */ |
||
257 | 2 | protected function getResponseHeaders() |
|
265 | } |
||
266 |