vendor/symfony/http-kernel/EventListener/StreamedResponseListener.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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\HttpFoundation\StreamedResponse;
  13. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. /**
  16. * StreamedResponseListener is responsible for sending the Response
  17. * to the client.
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. *
  21. * @final
  22. */
  23. class StreamedResponseListener implements EventSubscriberInterface
  24. {
  25. /**
  26. * Filters the Response.
  27. */
  28. public function onKernelResponse(ResponseEvent $event)
  29. {
  30. if (!$event->isMainRequest()) {
  31. return;
  32. }
  33. $response = $event->getResponse();
  34. if ($response instanceof StreamedResponse) {
  35. $response->send();
  36. }
  37. }
  38. public static function getSubscribedEvents(): array
  39. {
  40. return [
  41. KernelEvents::RESPONSE => ['onKernelResponse', -1024],
  42. ];
  43. }
  44. }