<?php
namespace App\Controller\Web\Catchalls;
use App\Component\Blobs\BlobConsumers\DepartmentBlobConsumer;
use App\Controller\Web\Sites\AbstractSiteController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
/**
*
*/
final class SitesController extends AbstractSiteController
{
const ROUTES__CATCHALL__ROBOTS = 'app.web.sites.default.catchall.robots';
const ROUTES__CATCHALL__SITEMAP = 'app.web.sites.default.catchall.sitemap';
const ROUTES__CATCHALL__ROOT = 'app.web.sites.default.catchall.root';
const ROUTES__CATCHALL__SUB = 'app.web.sites.default.catchall.sub';
// DI
protected DepartmentBlobConsumer $departmentBlobConsumer;
/**
* @param DepartmentBlobConsumer $departmentBlobConsumer
*/
public function __construct(DepartmentBlobConsumer $departmentBlobConsumer)
{
$this->departmentBlobConsumer = $departmentBlobConsumer;
}
/**
* @param string $host
* @return Response
*
* @Route(
* "/robots.txt",
* name = self::ROUTES__CATCHALL__ROBOTS,
* )
*/
public function robotsAction(string $host): Response
{
// close the session as it isn't needed on the frontend
$this->closeSession();
// get the domain
$domain = $this->determineDomain($host);
// get the site for the domain
$site = $this->determineSite($domain);
// get the file content of the robots for the tenant
$content = $this->departmentBlobConsumer->getRobots($site);
// if there is no content, throw a 404
if ( ! $content) {
throw new NotFoundHttpException();
}
// send back a response
return new Response(
$content,
Response::HTTP_OK,
[
'Content-Type' => 'text/plain',
]
);
}
/**
* @param string $host
* @return Response
*
* @Route(
* "/sitemap.xml",
* name = self::ROUTES__CATCHALL__SITEMAP,
* )
*/
public function sitemapAction(string $host): Response
{
// close the session as it isn't needed on the frontend
$this->closeSession();
// get the domain
$domain = $this->determineDomain($host);
// get the site for the domain
$site = $this->determineSite($domain);
// get the file content of the robots for the tenant
$content = $this->departmentBlobConsumer->getSitemap($site);
// if there is no content, throw a 404
if ( ! $content) {
throw new NotFoundHttpException();
}
// send back a response
return new Response(
$content,
Response::HTTP_OK,
[
'Content-Type' => 'application/xml',
]
);
}
/**
* @param string $host
* @param string|null $path
* @return Response
*
* @Route(
* "",
* name = self::ROUTES__CATCHALL__ROOT,
* )
* @Route(
* "/{path}",
* name = self::ROUTES__CATCHALL__SUB,
* requirements = {
* "path" = ".*",
* },
* )
*/
public function catchallAction(string $host, ?string $path = null): Response
{
return $this->legacy();
}
}