<?php
namespace App\Controller;
use App\DTO\AppDTO;
use App\Service\Sitemap\Sitemap;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
class SitemapController extends AbstractASController
{
protected EntityManagerInterface $em;
protected CacheInterface $Cache;
protected AppDTO $app;
//Repositories
public function __construct(private Sitemap $sitemap, RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
#[Route('/sitemap', name: 'app_sitemap_no_locale', priority: 100, defaults: ['_locale' => '%app.default_lang%'])]
#[Route(path: '/{_locale}/sitemap', name: 'app_sitemap', priority: 100, requirements: ['_locale' => '%app.langs%'])]
public function index(): Response
{
$this->sitemap->create();
$sitemap = $this->sitemap->get();
$xml = $this->sitemap->draw();
return new Response($xml, 200, ['Content-Type' => 'text/xml']);
}
}