<?phpdeclare(strict_types=1);namespace Klaravik\Sitemap\Controller;use Klaravik\Controller\Controller;use Klaravik\Sitemap\Service\SitemapServiceInterface;use Symfony\Component\HttpFoundation\Response;class SitemapController extends Controller{ private const CACHE_MAX_AGE = 3600; private SitemapServiceInterface $sitemapService; public function __construct(SitemapServiceInterface $sitemapService) { $this->sitemapService = $sitemapService; } /** * Main sitemap index (sitemap.xml). */ public function index(): Response { $xml = $this->sitemapService->generateSitemapIndexXml( $this->sitemapService->getSitemapIndex() ); return $this->createXmlResponse($xml); } /** * Pages sitemap (pages.xml). */ public function pages(): Response { $xml = $this->sitemapService->generateSitemapXml( $this->sitemapService->getPagesSitemap() ); return $this->createXmlResponse($xml); } /** * Categories sitemap (categories.xml). */ public function categories(): Response { $xml = $this->sitemapService->generateSitemapXml( $this->sitemapService->getCategoriesSitemap() ); return $this->createXmlResponse($xml); } /** * Active auctions sitemap (active_auctions.xml). */ public function activeAuctions(): Response { $xml = $this->sitemapService->generateSitemapXml( $this->sitemapService->getActiveAuctionsSitemap() ); return $this->createXmlResponse($xml); } /** * Closed auctions index (closed_auctions.xml). */ public function closedAuctionsIndex(): Response { $xml = $this->sitemapService->generateSitemapIndexXml( $this->sitemapService->getClosedAuctionsIndex() ); return $this->createXmlResponse($xml); } /** * Closed auctions for a specific month (closedAuctions{YYYYMM}.xml). */ public function closedAuctionsMonth(string $date): Response { $items = $this->sitemapService->getClosedAuctionsForMonth($date); if ($items === null) { throw $this->createNotFoundException('No closed auctions for this month'); } $xml = $this->sitemapService->generateSitemapXml($items); return $this->createXmlResponse($xml); } /** * Create XML response with proper headers and caching. */ private function createXmlResponse(string $xml): Response { $response = new Response($xml); $response->headers->set('Content-Type', 'application/xml; charset=UTF-8'); $response->setPublic(); $response->setMaxAge(self::CACHE_MAX_AGE); $response->headers->set('X-Robots-Tag', 'noindex'); return $response; }}