RequestEvent.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 RequestEvent extends KernelEvent
  22. {
  23. private $response;
  24. /**
  25. * Returns the response object.
  26. *
  27. * @return Response|null
  28. */
  29. public function getResponse()
  30. {
  31. return $this->response;
  32. }
  33. /**
  34. * Sets a response and stops event propagation.
  35. */
  36. public function setResponse(Response $response)
  37. {
  38. $this->response = $response;
  39. $this->stopPropagation();
  40. }
  41. /**
  42. * Returns whether a response was set.
  43. *
  44. * @return bool Whether a response was set
  45. */
  46. public function hasResponse()
  47. {
  48. return null !== $this->response;
  49. }
  50. }