KernelEvent.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 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 int $requestType The request type the kernel is currently processing; one of
  26. * HttpKernelInterface::MASTER_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::MASTER_REQUEST and
  56. * HttpKernelInterface::SUB_REQUEST
  57. */
  58. public function getRequestType()
  59. {
  60. return $this->requestType;
  61. }
  62. /**
  63. * Checks if this is a master request.
  64. *
  65. * @return bool True if the request is a master request
  66. */
  67. public function isMasterRequest()
  68. {
  69. return HttpKernelInterface::MASTER_REQUEST === $this->requestType;
  70. }
  71. }