<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class SeoController extends AbstractController
{
#[Route('robots.txt', name: 'sitemap')]
public function robots(): Response
{
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
return $this->render('robots.txt.twig', response: $response);
}
#[Route(path: [
'en_GB' => '/en/sitemap.xml',
'fr_FR' => '/fr/sitemap.xml',
], name: 'sitemap')]
public function sitemap(Request $request, ParameterBagInterface $bag): BinaryFileResponse
{
$file = sprintf('%s/public/sitemap-%s.xml', $bag->get('kernel.project_dir'), $request->getLocale());
if (!file_exists($file)) {
throw $this->createNotFoundException();
}
return new BinaryFileResponse($file);
}
}