KernelEvent.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\HttpKernel\HttpKernelInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\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. /**
  22. * The kernel in which this event was thrown.
  23. *
  24. * @var HttpKernelInterface
  25. */
  26. private $kernel;
  27. /**
  28. * The request the kernel is currently processing.
  29. *
  30. * @var Request
  31. */
  32. private $request;
  33. /**
  34. * The request type the kernel is currently processing. One of
  35. * HttpKernelInterface::MASTER_REQUEST and HttpKernelInterface::SUB_REQUEST.
  36. *
  37. * @var int
  38. */
  39. private $requestType;
  40. public function __construct(HttpKernelInterface $kernel, Request $request, $requestType)
  41. {
  42. $this->kernel = $kernel;
  43. $this->request = $request;
  44. $this->requestType = $requestType;
  45. }
  46. /**
  47. * Returns the kernel in which this event was thrown.
  48. *
  49. * @return HttpKernelInterface
  50. */
  51. public function getKernel()
  52. {
  53. return $this->kernel;
  54. }
  55. /**
  56. * Returns the request the kernel is currently processing.
  57. *
  58. * @return Request
  59. */
  60. public function getRequest()
  61. {
  62. return $this->request;
  63. }
  64. /**
  65. * Returns the request type the kernel is currently processing.
  66. *
  67. * @return int One of HttpKernelInterface::MASTER_REQUEST and
  68. * HttpKernelInterface::SUB_REQUEST
  69. */
  70. public function getRequestType()
  71. {
  72. return $this->requestType;
  73. }
  74. /**
  75. * Checks if this is a master request.
  76. *
  77. * @return bool True if the request is a master request
  78. */
  79. public function isMasterRequest()
  80. {
  81. return HttpKernelInterface::MASTER_REQUEST === $this->requestType;
  82. }
  83. }