public function addUrl(Url $loc, DateTime $lastmod = null, $changefreq = null, $priority = null) { // check length $url = $loc->getUrl(); if (strlen($url) >= 2048) { throw new Exception('Location value must be less than 2048 characters'); } $this->writer->startElement('url'); $this->writer->writeElement('loc', $url); if ($lastmod !== null) { $this->writer->writeElement('lastmod', $lastmod->format(DateTime::W3C)); } if ($changefreq !== null) { if (in_array($changefreq, self::$freq)) { $this->writer->writeElement('changefreq', $changefreq); } else { throw new Exception('Invalid change frequence must be one of ' . implode(', ', self::$freq)); } } if ($priority !== null) { $priority = (double) $priority; if ($priority >= 0.0 && $priority <= 1.0) { $this->writer->writeElement('priority', $priority); } else { throw new Exception('Invalid priority must be between 0.0 and 0.1'); } } $this->writer->endElement(); }