KernelEvent.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. private HttpKernelInterface $kernel;
  22. private Request $request;
  23. private ?int $requestType;
  24. /**
  25. * @param int $requestType The request type the kernel is currently processing; one of
  26. * HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST
  27. */
  28. public function __construct(HttpKernelInterface $kernel, Request $request, ?int $requestType)
  29. {
  30. $this->kernel = $kernel;
  31. $this->request = $request;
  32. $this->requestType = $requestType;
  33. }
  34. /**
  35. * Returns the kernel in which this event was thrown.
  36. */
  37. public function getKernel(): HttpKernelInterface
  38. {
  39. return $this->kernel;
  40. }
  41. /**
  42. * Returns the request the kernel is currently processing.
  43. */
  44. public function getRequest(): Request
  45. {
  46. return $this->request;
  47. }
  48. /**
  49. * Returns the request type the kernel is currently processing.
  50. *
  51. * @return int One of HttpKernelInterface::MAIN_REQUEST and
  52. * HttpKernelInterface::SUB_REQUEST
  53. */
  54. public function getRequestType(): int
  55. {
  56. return $this->requestType;
  57. }
  58. /**
  59. * Checks if this is the main request.
  60. */
  61. public function isMainRequest(): bool
  62. {
  63. return HttpKernelInterface::MAIN_REQUEST === $this->requestType;
  64. }
  65. }