src/Controller/RobotsTxtController.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Services\Http\RobotsTxtBuilder;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpKernel\Attribute\AsController;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. #[AsController]
  9. final class RobotsTxtController
  10. {
  11.     public function __construct(
  12.         private readonly RobotsTxtBuilder $robotsTxtBuilder,
  13.     ) {
  14.     }
  15.     #[Route(path'/robots.txt'name'robots_txt'methods: ['GET'])]
  16.     public function __invoke(): Response
  17.     {
  18.         return new Response(
  19.             $this->robotsTxtBuilder->build(),
  20.             Response::HTTP_OK,
  21.             [
  22.                 'Content-Type' => 'text/plain; charset=UTF-8',
  23.                 'Cache-Control' => 'public, max-age=3600',
  24.             ],
  25.         );
  26.     }
  27. }