/**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format(Response $response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     foreach ($response->data as $value) {
         $this->_sitemap->add($value['loc'], Helper::getValue($value['lastmod']), Helper::getValue($value['changefreq']), isset($value['priority']) ? $value['priority'] : null);
     }
     $response->content = $this->_sitemap->toString();
 }
    public function testToString()
    {
        $expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://foo.com</loc>
    <lastmod>2005-01-02T00:00:00+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1</priority>
  </url>
  <url>
    <loc>http://foo.com/about</loc>
    <lastmod>2005-01-01T00:00:00+00:00</lastmod>
  </url>
</urlset>

XML;
        $sitemap = new Sitemap();
        $sitemap->add('http://foo.com', '2005-01-02', ChangeFrequency::WEEKLY, 1.0);
        $sitemap->add('http://foo.com/about', '2005-01-01');
        $this->assertEquals($expected, $sitemap->toString());
    }
 public function renderDefault()
 {
     $cache = new Cache($this->cacheStorage, 'sitemap');
     $string = $cache->load('full', function (&$dependencies) {
         $dependencies[Cache::EXPIRE] = '1 day';
         $map = new Cartographer\Sitemap();
         $map->add($this->link('//Auth:registration'), NULL, Freq::YEARLY);
         $map->add($this->link('//Auth:resetPassword'), NULL, Freq::YEARLY);
         $map->add($this->link('//Homepage:default'), filemtime(__DIR__ . '/../templates/views/Homepage/default.latte'), Freq::YEARLY);
         $map->add($this->link('//Text:about'), filemtime(__DIR__ . '/../templates/views/Text/about.latte'), Freq::YEARLY);
         foreach ($this->orm->schemas->findAll() as $schema) {
             $map->add($this->absoluteLink($schema), NULL, Freq::MONTHLY);
         }
         foreach ($this->orm->blocks->findAll() as $block) {
             $map->add($this->absoluteLink($block), NULL, Freq::MONTHLY);
         }
         foreach ($this->orm->contents->findAll() as $content) {
             $map->add($this->absoluteLink($content), NULL, Freq::YEARLY);
         }
         return $map->toString();
     });
     $this->getHttpResponse()->setContentType('application/xml');
     $this->sendResponse(new TextResponse($string));
 }