1 | <?php |
||
11 | class SitemapFactory |
||
12 | { |
||
13 | /** |
||
14 | * @var FilesystemInterface |
||
15 | */ |
||
16 | protected $filesystem = null; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $baseUrl = ''; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $filesCreated = []; |
||
27 | |||
28 | /** |
||
29 | * @param FilesystemInterface $filesystem |
||
30 | */ |
||
31 | public function __construct(FilesystemInterface $filesystem) |
||
35 | |||
36 | /** |
||
37 | * Gets the Filesystem. |
||
38 | * @return FilesystemInterface |
||
39 | */ |
||
40 | public function getFilesystem() |
||
44 | |||
45 | /** |
||
46 | * Sets the Base URL for sitemap files. |
||
47 | * |
||
48 | * @param string $baseUrl |
||
49 | * @return $this |
||
50 | */ |
||
51 | public function setBaseUrl($baseUrl) |
||
57 | |||
58 | /** |
||
59 | * Gets the Base URL for sitemap files. |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getBaseUrl() |
||
66 | |||
67 | /** |
||
68 | * Gets the array of files created. |
||
69 | * @return array |
||
70 | */ |
||
71 | public function getFilesCreated() |
||
75 | |||
76 | /** |
||
77 | * @return AbstractSitemap |
||
78 | */ |
||
79 | protected function instantiateNewSitemap() |
||
83 | |||
84 | protected function addEntry($entry, Sitemap $sitemap) |
||
89 | |||
90 | /** |
||
91 | * Generates the sitemap(s) using the iterator previously set. |
||
92 | * @param \Iterator $iterator |
||
93 | * @throws \RuntimeException |
||
94 | * @return string The URL for the entry Sitemap |
||
95 | */ |
||
96 | public function createSitemap(Iterator $iterator) |
||
117 | |||
118 | /** |
||
119 | * Creates a Sitemap index given an Iterator of Sitemaps |
||
120 | * @param Iterator $sitemaps |
||
121 | * @return mixed |
||
122 | */ |
||
123 | public function createSitemapIndex(Iterator $sitemaps) |
||
153 | |||
154 | /** |
||
155 | * Writes the given sitemap to the filesystem. The filename pattern is: |
||
156 | * {MD5_Hash}.{Class_Name}.{Index}.xml |
||
157 | * @param string $groupName |
||
158 | * @param AbstractSitemap $sitemap |
||
159 | * @return string The filename of the sitemap written |
||
160 | */ |
||
161 | protected function writeSitemap($groupName, AbstractSitemap $sitemap) |
||
173 | |||
174 | /** |
||
175 | * Parses the given Entry into its constituent parts. |
||
176 | * @param mixed $entry The entry to parse |
||
177 | * @return array |
||
178 | * @throws \InvalidArgumentException |
||
179 | */ |
||
180 | protected function parseEntry($entry) |
||
192 | |||
193 | /** |
||
194 | * Generates a random MD5 hash. |
||
195 | * @return string |
||
196 | * @throws \RuntimeException |
||
197 | */ |
||
198 | protected function randomHash() |
||
202 | |||
203 | /** |
||
204 | * Gets the Full URL for the given file. |
||
205 | * @param string $file |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function fileUrl($file) |
||
212 | |||
213 | /** |
||
214 | * Generates a string of random bytes (of given length). |
||
215 | * @param integer $bytes The number of bytes to return. |
||
216 | * @throws \RuntimeException |
||
217 | * @return string |
||
218 | * @codeCoverageIgnore |
||
219 | */ |
||
220 | protected function randomBytes($bytes = 32) |
||
230 | } |
||
231 |