KernelEvent.php 1.7 KB

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