HttpResponseSender.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Mvc\ResponseSender;
  10. use Zend\Http\Response;
  11. class HttpResponseSender extends AbstractResponseSender
  12. {
  13. /**
  14. * Send content
  15. *
  16. * @param SendResponseEvent $event
  17. * @return HttpResponseSender
  18. */
  19. public function sendContent(SendResponseEvent $event)
  20. {
  21. if ($event->contentSent()) {
  22. return $this;
  23. }
  24. $response = $event->getResponse();
  25. echo $response->getContent();
  26. $event->setContentSent();
  27. return $this;
  28. }
  29. /**
  30. * Send HTTP response
  31. *
  32. * @param SendResponseEvent $event
  33. * @return HttpResponseSender
  34. */
  35. public function __invoke(SendResponseEvent $event)
  36. {
  37. $response = $event->getResponse();
  38. if (!$response instanceof Response) {
  39. return $this;
  40. }
  41. $this->sendHeaders($event)
  42. ->sendContent($event);
  43. $event->stopPropagation(true);
  44. return $this;
  45. }
  46. }