GetResponseEvent.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Event;
  11. use Symfony\Component\HttpFoundation\Response;
  12. /**
  13. * Allows to create a response for a request.
  14. *
  15. * Call setResponse() to set the response that will be returned for the
  16. * current request. The propagation of this event is stopped as soon as a
  17. * response is set.
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. */
  21. class GetResponseEvent extends KernelEvent
  22. {
  23. /**
  24. * The response object.
  25. *
  26. * @var Response
  27. */
  28. private $response;
  29. /**
  30. * Returns the response object.
  31. *
  32. * @return Response
  33. */
  34. public function getResponse()
  35. {
  36. return $this->response;
  37. }
  38. /**
  39. * Sets a response and stops event propagation.
  40. *
  41. * @param Response $response
  42. */
  43. public function setResponse(Response $response)
  44. {
  45. $this->response = $response;
  46. $this->stopPropagation();
  47. }
  48. /**
  49. * Returns whether a response was set.
  50. *
  51. * @return bool Whether a response was set
  52. */
  53. public function hasResponse()
  54. {
  55. return null !== $this->response;
  56. }
  57. }