request->hostInfo; $item = [ 'loc' => $host . $url, 'changefreq' => $changeFreq, 'priority' => $priority ]; if ($lastMod) { $item['lastmod'] = $this->dateToW3C($lastMod); } $this->items[] = $item; } /** * @return string XML code */ public function render() { $dom = new DOMDocument('1.0', 'utf-8'); $urlset = $dom->createElement('urlset'); $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($this->items as $item) { $url = $dom->createElement('url'); foreach ($item as $key => $value) { $elem = $dom->createElement($key); $elem->appendChild($dom->createTextNode($value)); $url->appendChild($elem); } $urlset->appendChild($url); } $dom->appendChild($urlset); return $dom->saveXML(); } protected function dateToW3C($date) { if (is_int($date)) { return date(DATE_W3C, $date); } else { return date(DATE_W3C, strtotime($date)); } } }