<?php
declare(strict_types=1);
namespace App\Robots;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class AddDefaultRobotsOnKernelResponse implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => ['onResponse', -1000],
];
}
public function onResponse(ResponseEvent $event): void
{
if ($event->getRequest()->isXmlHttpRequest()) {
return;
}
$response = $event->getResponse();
if ($response->headers->has(Robots::ROBOT_HEADER_TAG)) {
return;
}
$response->headers->set(Robots::ROBOT_HEADER_TAG, Robots::ROBOTS_INDEX_FOLLOW->value);
}
}