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