GetResponseEvent.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * @api
  22. */
  23. class GetResponseEvent extends KernelEvent
  24. {
  25. /**
  26. * The response object
  27. * @var Response
  28. */
  29. private $response;
  30. /**
  31. * Returns the response object
  32. *
  33. * @return Response
  34. *
  35. * @api
  36. */
  37. public function getResponse()
  38. {
  39. return $this->response;
  40. }
  41. /**
  42. * Sets a response and stops event propagation
  43. *
  44. * @param Response $response
  45. *
  46. * @api
  47. */
  48. public function setResponse(Response $response)
  49. {
  50. $this->response = $response;
  51. $this->stopPropagation();
  52. }
  53. /**
  54. * Returns whether a response was set
  55. *
  56. * @return Boolean Whether a response was set
  57. *
  58. * @api
  59. */
  60. public function hasResponse()
  61. {
  62. return null !== $this->response;
  63. }
  64. }