1 | <?php |
||
7 | class DomainEventPublisher |
||
8 | { |
||
9 | /** |
||
10 | * @var DomainEventPublisher |
||
11 | */ |
||
12 | private static $instance; |
||
13 | |||
14 | /** |
||
15 | * @var DomainEventSubscriber[][] |
||
16 | */ |
||
17 | private $subscribers; |
||
18 | |||
19 | /** |
||
20 | * Returns an instance of the publisher. |
||
21 | * @return DomainEventPublisher |
||
22 | */ |
||
23 | 3 | public static function instance() : DomainEventPublisher |
|
27 | |||
28 | /** |
||
29 | * Publishes a domain event by notifying all the subscribers subscribed to |
||
30 | * this event type. Subscribers can be notified for all events if they |
||
31 | * subscribe to DomainEvent::class. |
||
32 | * @param DomainEvent $event |
||
33 | */ |
||
34 | 3 | public function publish(DomainEvent $event) |
|
51 | |||
52 | /** |
||
53 | * Resets the publisher by removing all the current subscribers. |
||
54 | */ |
||
55 | 1 | public function reset() |
|
59 | |||
60 | /** |
||
61 | * @param DomainEventSubscriber $subscriber |
||
62 | */ |
||
63 | 3 | public function subscribe(DomainEventSubscriber $subscriber) |
|
67 | |||
68 | /** |
||
69 | * The constructor. |
||
70 | */ |
||
71 | 3 | private function __construct() |
|
75 | |||
76 | /** |
||
77 | * Clones the publisher. |
||
78 | */ |
||
79 | private function __clone() |
||
82 | } |
||
83 |