KernelEvent.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\EventDispatcher\Event;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpKernel\HttpKernelInterface;
  14. /**
  15. * Base class for events thrown in the HttpKernel component.
  16. *
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. class KernelEvent extends Event
  20. {
  21. private $kernel;
  22. private $request;
  23. private $requestType;
  24. /**
  25. * @param HttpKernelInterface $kernel The kernel in which this event was thrown
  26. * @param Request $request The request the kernel is currently processing
  27. * @param int $requestType The request type the kernel is currently processing; one of
  28. * HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST
  29. */
  30. public function __construct(HttpKernelInterface $kernel, Request $request, ?int $requestType)
  31. {
  32. $this->kernel = $kernel;
  33. $this->request = $request;
  34. $this->requestType = $requestType;
  35. }
  36. /**
  37. * Returns the kernel in which this event was thrown.
  38. *
  39. * @return HttpKernelInterface
  40. */
  41. public function getKernel()
  42. {
  43. return $this->kernel;
  44. }
  45. /**
  46. * Returns the request the kernel is currently processing.
  47. *
  48. * @return Request
  49. */
  50. public function getRequest()
  51. {
  52. return $this->request;
  53. }
  54. /**
  55. * Returns the request type the kernel is currently processing.
  56. *
  57. * @return int One of HttpKernelInterface::MASTER_REQUEST and
  58. * HttpKernelInterface::SUB_REQUEST
  59. */
  60. public function getRequestType()
  61. {
  62. return $this->requestType;
  63. }
  64. /**
  65. * Checks if this is a master request.
  66. *
  67. * @return bool True if the request is a master request
  68. */
  69. public function isMasterRequest()
  70. {
  71. return HttpKernelInterface::MASTER_REQUEST === $this->requestType;
  72. }
  73. }