<?php
declare(strict_types=0);
/*
* WellCommerce Foundation
*
* This file is part of the WellCommerce package.
*
* (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/
namespace WellCommerce\Bundle\AppBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use WellCommerce\Bundle\CoreBundle\DependencyInjection\AbstractServiceSubscriber;
/**
* Class LocaleSubscriber
*
* @author Adam Piotrowski <adam@wellcommerce.org>
*/
class RobotsSubscriber extends AbstractServiceSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => ['onKernelResponse', -300],
];
}
public function onKernelResponse(ResponseEvent $event)
{
if ($event->getRequestType() == HttpKernelInterface::SUB_REQUEST) {
return;
}
if ($this->getRequestHelper()->isGraphQLRequest()) {
return;
}
if ($this->getSecurityHelper()->isActiveAdminFirewall()) {
return;
}
$response = $event->getResponse();
$directives = $this->getMetadataHelper()->getDirectives();
if (!empty($directives)) {
$response->headers->set('X-Robots-Tag', implode(',', $directives), true);
}
}
}