Nenhuma descrição

KernelEvent.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 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. }