| @@ 12-67 (lines=56) @@ | ||
| 9 | * |
|
| 10 | * @package Thepixeldeveloper\Sitemap |
|
| 11 | */ |
|
| 12 | class SitemapIndex implements OutputInterface |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * Array of Sitemap entries. |
|
| 16 | * |
|
| 17 | * @var OutputInterface[] |
|
| 18 | */ |
|
| 19 | protected $sitemaps = []; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * Add a new Sitemap object to the collection. |
|
| 23 | * |
|
| 24 | * @param OutputInterface $sitemap |
|
| 25 | * |
|
| 26 | * @return $this |
|
| 27 | */ |
|
| 28 | public function addSitemap(OutputInterface $sitemap) |
|
| 29 | { |
|
| 30 | $this->sitemaps[] = $sitemap; |
|
| 31 | ||
| 32 | return $this; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * {@inheritdoc} |
|
| 37 | */ |
|
| 38 | public function generateXML(XMLWriter $XMLWriter) |
|
| 39 | { |
|
| 40 | $XMLWriter->startElement('sitemapindex'); |
|
| 41 | $XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
|
| 42 | ||
| 43 | $XMLWriter->writeAttribute( |
|
| 44 | 'xsi:schemaLocation', |
|
| 45 | 'http://www.sitemaps.org/schemas/sitemap/0.9 ' . |
|
| 46 | 'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd' |
|
| 47 | ); |
|
| 48 | ||
| 49 | $XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); |
|
| 50 | ||
| 51 | foreach ($this->getSitemaps() as $sitemap) { |
|
| 52 | $sitemap->generateXML($XMLWriter); |
|
| 53 | } |
|
| 54 | ||
| 55 | $XMLWriter->endElement(); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Get an array of Sitemap objects. |
|
| 60 | * |
|
| 61 | * @return OutputInterface[] |
|
| 62 | */ |
|
| 63 | public function getSitemaps() |
|
| 64 | { |
|
| 65 | return $this->sitemaps; |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| @@ 12-66 (lines=55) @@ | ||
| 9 | * |
|
| 10 | * @package Thepixeldeveloper\Sitemap |
|
| 11 | */ |
|
| 12 | class Urlset implements OutputInterface |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * Array of URL objects. |
|
| 16 | * |
|
| 17 | * @var OutputInterface[] |
|
| 18 | */ |
|
| 19 | protected $urls = []; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * Add a new URL object. |
|
| 23 | * |
|
| 24 | * @param OutputInterface $url |
|
| 25 | * |
|
| 26 | * @return $this |
|
| 27 | */ |
|
| 28 | public function addUrl(OutputInterface $url) |
|
| 29 | { |
|
| 30 | $this->urls[] = $url; |
|
| 31 | ||
| 32 | return $this; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * {@inheritdoc} |
|
| 37 | */ |
|
| 38 | public function generateXML(XMLWriter $XMLWriter) |
|
| 39 | { |
|
| 40 | $XMLWriter->startElement('urlset'); |
|
| 41 | ||
| 42 | $XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
|
| 43 | ||
| 44 | $XMLWriter->writeAttribute('xsi:schemaLocation', |
|
| 45 | 'http://www.sitemaps.org/schemas/sitemap/0.9 ' . |
|
| 46 | 'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd'); |
|
| 47 | ||
| 48 | $XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); |
|
| 49 | ||
| 50 | foreach ($this->getUrls() as $url) { |
|
| 51 | $url->generateXML($XMLWriter); |
|
| 52 | } |
|
| 53 | ||
| 54 | $XMLWriter->endElement(); |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * Get array of URL objects. |
|
| 59 | * |
|
| 60 | * @return OutputInterface[] |
|
| 61 | */ |
|
| 62 | public function getUrls() |
|
| 63 | { |
|
| 64 | return $this->urls; |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||