NullDispatcher.php 3.0 KB

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