-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventDispatcher.php
89 lines (75 loc) · 2.07 KB
/
EventDispatcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Qubus\EventDispatcher
*
* @link https://github.com/QubusPHP/event-dispatcher
* @copyright 2020 Joshua Parker <joshua@joshuaparker.dev>
* @copyright 2018 Filip Štamcar (original author Tor Morten Jensen)
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
declare(strict_types=1);
namespace Qubus\EventDispatcher;
interface EventDispatcher
{
/**
* Low priority.
*
* @var int PRIORITY_LOW
*/
public const PRIORITY_LOW = -100;
/**
* Default priority.
*
* @var int PRIORITY_DEFAULT
*/
public const PRIORITY_DEFAULT = 0;
/**
* High priority.
*
* @var int PRIORITY_HIGH
*/
public const PRIORITY_HIGH = 100;
/**
* Dispatches an event to all registered listeners.
*
* @param string|Event $eventName
*/
public function dispatch($eventName, ?Event $event = null);
/**
* Registries a listener for the event.
*
* @param EventListener|callable $listener
*/
public function addListener(string $eventName, $listener, int $priority = self::PRIORITY_DEFAULT);
/**
* Registries a subscriber.
*/
public function addSubscriber(EventSubscriber $subscriber);
/**
* Removes a listener from the specified event.
*
* @param EventListener|callable $listener
*/
public function removeListener(string $eventName, $listener);
/**
* Removes a subscriber.
*/
public function removeSubscriber(EventSubscriber $subscriber);
/**
* Removes all listeners from the specified event.
*/
public function removeAllListeners(?string $eventName = null);
/**
* Checks whether the listener is existed for the event.
*
* @param EventListener|callable $listener
*/
public function hasListener(string $eventName, $listener): bool;
/**
* Gets all listeners of the event or all registered listeners.
*
* @param string|null $eventName
* @return array
*/
public function getListeners(?string $eventName = null): array;
}