vendor/symfony/http-kernel/EventListener/DisallowRobotsIndexingListener.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <[email protected]>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\EventListener;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. /**
  15. * Ensures that the application is not indexed by search engines.
  16. *
  17. * @author Gary PEGEOT <[email protected]>
  18. */
  19. class DisallowRobotsIndexingListener implements EventSubscriberInterface
  20. {
  21. private const HEADER_NAME = 'X-Robots-Tag';
  22. public function onResponse(ResponseEvent $event): void
  23. {
  24. if (!$event->getResponse()->headers->has(static::HEADER_NAME)) {
  25. $event->getResponse()->headers->set(static::HEADER_NAME, 'noindex');
  26. }
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function getSubscribedEvents()
  32. {
  33. return [
  34. KernelEvents::RESPONSE => ['onResponse', -255],
  35. ];
  36. }
  37. }