src/WellCommerce/Bundle/AppBundle/EventListener/RobotsSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=0);
  3. /*
  4.  * WellCommerce Foundation
  5.  *
  6.  * This file is part of the WellCommerce package.
  7.  *
  8.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  9.  *
  10.  * For the full copyright and license information,
  11.  * please view the LICENSE file that was distributed with this source code.
  12.  */
  13. namespace WellCommerce\Bundle\AppBundle\EventListener;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  16. use Symfony\Component\HttpKernel\HttpKernelInterface;
  17. use Symfony\Component\HttpKernel\KernelEvents;
  18. use WellCommerce\Bundle\CoreBundle\DependencyInjection\AbstractServiceSubscriber;
  19. /**
  20.  * Class LocaleSubscriber
  21.  *
  22.  * @author  Adam Piotrowski <adam@wellcommerce.org>
  23.  */
  24. class RobotsSubscriber extends AbstractServiceSubscriber implements EventSubscriberInterface
  25. {
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             KernelEvents::RESPONSE => ['onKernelResponse', -300],
  30.         ];
  31.     }
  32.     public function onKernelResponse(ResponseEvent $event)
  33.     {
  34.         if ($event->getRequestType() == HttpKernelInterface::SUB_REQUEST) {
  35.             return;
  36.         }
  37.         if ($this->getRequestHelper()->isGraphQLRequest()) {
  38.             return;
  39.         }
  40.         if ($this->getSecurityHelper()->isActiveAdminFirewall()) {
  41.             return;
  42.         }
  43.         $response   $event->getResponse();
  44.         $directives $this->getMetadataHelper()->getDirectives();
  45.         if (!empty($directives)) {
  46.             $response->headers->set('X-Robots-Tag'implode(','$directives), true);
  47.         }
  48.     }
  49. }