Conditions | 3 |
Paths | 4 |
Total Lines | 19 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | public function __invoke(): string |
||
27 | { |
||
28 | $documents = $this->source->all(); |
||
29 | $xml = new SimpleXMLElement( |
||
30 | "<?xml version='1.0' encoding='UTF-8' ?>\n" |
||
31 | . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />' |
||
32 | ); |
||
33 | foreach ($documents as $document) { |
||
34 | assert($document instanceof Document); |
||
35 | $item = $xml->addChild('url'); |
||
36 | $item->addChild('loc', ($this->config->get('base_url') ?? '') . $document->getUrl()); |
||
37 | } |
||
38 | $doc = new DOMDocument(); |
||
39 | $doc->preserveWhiteSpace = false; |
||
40 | $doc->formatOutput = true; |
||
41 | if ($content = $xml->asXML()) { |
||
42 | $doc->loadXML($content); |
||
43 | } |
||
44 | return $doc->saveXML(); |
||
45 | } |
||
47 |