NullDispatcher.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace Illuminate\Events;
  3. use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
  4. use Illuminate\Support\Traits\ForwardsCalls;
  5. class NullDispatcher implements DispatcherContract
  6. {
  7. use ForwardsCalls;
  8. /**
  9. * The underlying event dispatcher instance.
  10. *
  11. * @var \Illuminate\Contracts\Events\Dispatcher
  12. */
  13. protected $dispatcher;
  14. /**
  15. * Create a new event dispatcher instance that does not fire.
  16. *
  17. * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
  18. */
  19. public function __construct(DispatcherContract $dispatcher)
  20. {
  21. $this->dispatcher = $dispatcher;
  22. }
  23. /**
  24. * Don't fire an event.
  25. *
  26. * @param string|object $event
  27. * @param mixed $payload
  28. * @param bool $halt
  29. * @return void
  30. */
  31. public function dispatch($event, $payload = [], $halt = false)
  32. {
  33. //
  34. }
  35. /**
  36. * Don't register an event and payload to be fired later.
  37. *
  38. * @param string $event
  39. * @param array $payload
  40. * @return void
  41. */
  42. public function push($event, $payload = [])
  43. {
  44. //
  45. }
  46. /**
  47. * Don't dispatch an event.
  48. *
  49. * @param string|object $event
  50. * @param mixed $payload
  51. * @return mixed
  52. */
  53. public function until($event, $payload = [])
  54. {
  55. //
  56. }
  57. /**
  58. * Register an event listener with the dispatcher.
  59. *
  60. * @param \Closure|string|array $events
  61. * @param \Closure|string|array|null $listener
  62. * @return void
  63. */
  64. public function listen($events, $listener = null)
  65. {
  66. $this->dispatcher->listen($events, $listener);
  67. }
  68. /**
  69. * Determine if a given event has listeners.
  70. *
  71. * @param string $eventName
  72. * @return bool
  73. */
  74. public function hasListeners($eventName)
  75. {
  76. return $this->dispatcher->hasListeners($eventName);
  77. }
  78. /**
  79. * Register an event subscriber with the dispatcher.
  80. *
  81. * @param object|string $subscriber
  82. * @return void
  83. */
  84. public function subscribe($subscriber)
  85. {
  86. $this->dispatcher->subscribe($subscriber);
  87. }
  88. /**
  89. * Flush a set of pushed events.
  90. *
  91. * @param string $event
  92. * @return void
  93. */
  94. public function flush($event)
  95. {
  96. $this->dispatcher->flush($event);
  97. }
  98. /**
  99. * Remove a set of listeners from the dispatcher.
  100. *
  101. * @param string $event
  102. * @return void
  103. */
  104. public function forget($event)
  105. {
  106. $this->dispatcher->forget($event);
  107. }
  108. /**
  109. * Forget all of the queued listeners.
  110. *
  111. * @return void
  112. */
  113. public function forgetPushed()
  114. {
  115. $this->dispatcher->forgetPushed();
  116. }
  117. /**
  118. * Dynamically pass method calls to the underlying dispatcher.
  119. *
  120. * @param string $method
  121. * @param array $parameters
  122. * @return mixed
  123. */
  124. public function __call($method, $parameters)
  125. {
  126. return $this->forwardDecoratedCallTo($this->dispatcher, $method, $parameters);
  127. }
  128. }