vendor/symfony/http-kernel/Event/KernelEvent.php line 86

Open in your IDE?
  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 $kernel;
  22. private $request;
  23. private $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. * @return HttpKernelInterface
  38. */
  39. public function getKernel()
  40. {
  41. return $this->kernel;
  42. }
  43. /**
  44. * Returns the request the kernel is currently processing.
  45. *
  46. * @return Request
  47. */
  48. public function getRequest()
  49. {
  50. return $this->request;
  51. }
  52. /**
  53. * Returns the request type the kernel is currently processing.
  54. *
  55. * @return int One of HttpKernelInterface::MAIN_REQUEST and
  56. * HttpKernelInterface::SUB_REQUEST
  57. */
  58. public function getRequestType()
  59. {
  60. return $this->requestType;
  61. }
  62. /**
  63. * Checks if this is the main request.
  64. */
  65. public function isMainRequest(): bool
  66. {
  67. return HttpKernelInterface::MAIN_REQUEST === $this->requestType;
  68. }
  69. /**
  70. * Checks if this is a master request.
  71. *
  72. * @return bool
  73. *
  74. * @deprecated since symfony/http-kernel 5.3, use isMainRequest() instead
  75. */
  76. public function isMasterRequest()
  77. {
  78. trigger_deprecation('symfony/http-kernel', '5.3', '"%s()" is deprecated, use "isMainRequest()" instead.', __METHOD__);
  79. return $this->isMainRequest();
  80. }
  81. }