src/App/Controller/Web/Catchalls/SitesController.php line 127

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Web\Catchalls;
  3. use App\Component\Blobs\BlobConsumers\DepartmentBlobConsumer;
  4. use App\Controller\Web\Sites\AbstractSiteController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. /**
  9.  *
  10.  */
  11. final class SitesController extends AbstractSiteController
  12. {
  13.     const ROUTES__CATCHALL__ROBOTS 'app.web.sites.default.catchall.robots';
  14.     const ROUTES__CATCHALL__SITEMAP 'app.web.sites.default.catchall.sitemap';
  15.     const ROUTES__CATCHALL__ROOT 'app.web.sites.default.catchall.root';
  16.     const ROUTES__CATCHALL__SUB 'app.web.sites.default.catchall.sub';
  17.     // DI
  18.     protected DepartmentBlobConsumer $departmentBlobConsumer;
  19.     /**
  20.      * @param DepartmentBlobConsumer $departmentBlobConsumer
  21.      */
  22.     public function __construct(DepartmentBlobConsumer $departmentBlobConsumer)
  23.     {
  24.         $this->departmentBlobConsumer $departmentBlobConsumer;
  25.     }
  26.     /**
  27.      * @param string $host
  28.      * @return Response
  29.      *
  30.      * @Route(
  31.      *     "/robots.txt",
  32.      *     name = self::ROUTES__CATCHALL__ROBOTS,
  33.      * )
  34.      */
  35.     public function robotsAction(string $host): Response
  36.     {
  37.         // close the session as it isn't needed on the frontend
  38.         $this->closeSession();
  39.         // get the domain
  40.         $domain $this->determineDomain($host);
  41.         // get the site for the domain
  42.         $site $this->determineSite($domain);
  43.         // get the file content of the robots for the tenant
  44.         $content $this->departmentBlobConsumer->getRobots($site);
  45.         // if there is no content, throw a 404
  46.         if ( ! $content) {
  47.             throw new NotFoundHttpException();
  48.         }
  49.         // send back a response
  50.         return new Response(
  51.             $content,
  52.             Response::HTTP_OK,
  53.             [
  54.                 'Content-Type' => 'text/plain',
  55.             ]
  56.         );
  57.     }
  58.     /**
  59.      * @param string $host
  60.      * @return Response
  61.      *
  62.      * @Route(
  63.      *     "/sitemap.xml",
  64.      *     name = self::ROUTES__CATCHALL__SITEMAP,
  65.      * )
  66.      */
  67.     public function sitemapAction(string $host): Response
  68.     {
  69.         // close the session as it isn't needed on the frontend
  70.         $this->closeSession();
  71.         // get the domain
  72.         $domain $this->determineDomain($host);
  73.         // get the site for the domain
  74.         $site $this->determineSite($domain);
  75.         // get the file content of the robots for the tenant
  76.         $content $this->departmentBlobConsumer->getSitemap($site);
  77.         // if there is no content, throw a 404
  78.         if ( ! $content) {
  79.             throw new NotFoundHttpException();
  80.         }
  81.         // send back a response
  82.         return new Response(
  83.             $content,
  84.             Response::HTTP_OK,
  85.             [
  86.                 'Content-Type' => 'application/xml',
  87.             ]
  88.         );
  89.     }
  90.     /**
  91.      * @param string $host
  92.      * @param string|null $path
  93.      * @return Response
  94.      *
  95.      * @Route(
  96.      *     "",
  97.      *     name = self::ROUTES__CATCHALL__ROOT,
  98.      * )
  99.      * @Route(
  100.      *     "/{path}",
  101.      *     name = self::ROUTES__CATCHALL__SUB,
  102.      *     requirements = {
  103.      *         "path" = ".*",
  104.      *     },
  105.      * )
  106.      */
  107.     public function catchallAction(string $host, ?string $path null): Response
  108.     {
  109.         return $this->legacy();
  110.     }
  111. }