vendor/ibexa/system-info/src/bundle/EventSubscriber/AddXPoweredByHeader.php line 35

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\SystemInfo\EventSubscriber;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  10. use Symfony\Component\HttpKernel\KernelEvents;
  11. /**
  12. * Sets X-Powered-By header to promote use of Platform.
  13. */
  14. class AddXPoweredByHeader implements EventSubscriberInterface
  15. {
  16. /**
  17. * @var string If empty, this powered by header is skipped.
  18. */
  19. private $installationName;
  20. public function __construct(string $installationName)
  21. {
  22. $this->installationName = $installationName;
  23. }
  24. public static function getSubscribedEvents()
  25. {
  26. return [KernelEvents::RESPONSE => 'promotePlatform'];
  27. }
  28. public function promotePlatform(ResponseEvent $event): void
  29. {
  30. $response = $event->getResponse();
  31. if ($response->headers->has('X-Powered-By')) {
  32. return;
  33. }
  34. if ($this->installationName) {
  35. $response->headers->set('X-Powered-By', $this->installationName);
  36. }
  37. }
  38. }
  39. class_alias(AddXPoweredByHeader::class, 'EzSystems\EzSupportToolsBundle\EventSubscriber\AddXPoweredByHeader');