|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sebdesign\SM\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; |
|
6
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
7
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
8
|
|
|
|
|
9
|
|
|
class Dispatcher implements EventDispatcherInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var \Illuminate\Contracts\Events\Dispatcher |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $dispatcher; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher |
|
18
|
|
|
*/ |
|
19
|
99 |
|
public function __construct(DispatcherContract $dispatcher) |
|
20
|
|
|
{ |
|
21
|
99 |
|
$this->dispatcher = $dispatcher; |
|
22
|
33 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
39 |
|
public function dispatch(object $event, ?string $eventName = null): object |
|
28
|
|
|
{ |
|
29
|
39 |
|
if (is_null($eventName)) { |
|
30
|
|
|
$this->dispatcher->dispatch($event); |
|
31
|
|
|
} else { |
|
32
|
39 |
|
$this->dispatcher->dispatch($eventName, $event); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
39 |
|
return $event; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function addListener(string $eventName, callable $listener, int $priority = 0): void |
|
42
|
|
|
{ |
|
43
|
3 |
|
throw new \Exception('Please use `Event::listen()`.'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
3 |
|
public function addSubscriber(EventSubscriberInterface $subscriber): void |
|
50
|
|
|
{ |
|
51
|
3 |
|
throw new \Exception('Please use `Event::subscribe()`.'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
3 |
|
public function removeListener(string $eventName, callable $listener): void |
|
58
|
|
|
{ |
|
59
|
3 |
|
throw new \Exception('Please use `Event::forget()`.'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function removeSubscriber(EventSubscriberInterface $subscriber): void |
|
66
|
|
|
{ |
|
67
|
3 |
|
throw new \Exception('Removing event subscribers is not supported'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
3 |
|
public function getListeners(?string $eventName = null): array |
|
74
|
|
|
{ |
|
75
|
3 |
|
throw new \Exception('Please use `Event::getListeners()`.'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
3 |
|
public function getListenerPriority(string $eventName, $listener): ?int |
|
82
|
|
|
{ |
|
83
|
3 |
|
throw new \Exception('Event priority is not supported anymore in Laravel.'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
3 |
|
public function hasListeners(?string $eventName = null): bool |
|
90
|
|
|
{ |
|
91
|
3 |
|
throw new \Exception('Please use `Event::hasListeners()`.'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|