/
SitemapController.php
84 lines (71 loc) · 1.84 KB
/
SitemapController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* This file is part of the PrestaSitemapBundle package.
*
* (c) PrestaConcept <www.prestaconcept.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Presta\SitemapBundle\Controller;
use Presta\SitemapBundle\Service\GeneratorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* Provides action to render sitemap files
*
* @author David Epely <depely@prestaconcept.net>
*/
class SitemapController extends Controller
{
/**
* list sitemaps
*
* @return Response
*/
public function indexAction()
{
$sitemapindex = $this->getGenerator()->fetch('root');
if (!$sitemapindex) {
throw $this->createNotFoundException();
}
$response = Response::create($sitemapindex->toXml());
$response->setPublic();
$response->setClientTtl($this->getTtl());
return $response;
}
/**
* list urls of a section
*
* @param string $name
*
* @return Response
*/
public function sectionAction($name)
{
$section = $this->getGenerator()->fetch($name);
if (!$section) {
throw $this->createNotFoundException();
}
$response = Response::create($section->toXml());
$response->setPublic();
$response->setClientTtl($this->getTtl());
return $response;
}
/**
* Time to live of the response in seconds
*
* @return int
*/
protected function getTtl()
{
return $this->container->getParameter('presta_sitemap.timetolive');
}
/**
* @return GeneratorInterface
*/
private function getGenerator()
{
return $this->get('presta_sitemap.generator');
}
}