1 | <?php |
||
21 | class DomainEventPublisher |
||
22 | { |
||
23 | /** |
||
24 | * @var DomainEventPublisher |
||
25 | */ |
||
26 | private static $instance = null; |
||
27 | |||
28 | /** |
||
29 | * @var EventBus |
||
30 | */ |
||
31 | protected $eventBus; |
||
32 | |||
33 | /** |
||
34 | * @return DomainEventPublisher |
||
35 | */ |
||
36 | private static function instance() |
||
46 | |||
47 | /** |
||
48 | * @param EventBus $eventBus |
||
49 | */ |
||
50 | public static function set(EventBus $eventBus) |
||
54 | |||
55 | /** |
||
56 | * @return EventBus $eventBus |
||
57 | */ |
||
58 | public static function eventBus() |
||
62 | |||
63 | /** |
||
64 | * @param DomainEventInterface $event |
||
65 | */ |
||
66 | public static function publish(DomainEventInterface $event) |
||
70 | |||
71 | /** |
||
72 | * @param DomainEventSubscriberInterface $subscriber |
||
73 | */ |
||
74 | public static function subscribe(DomainEventSubscriberInterface $subscriber) |
||
78 | |||
79 | /** |
||
80 | * @param DomainEventInterface $event |
||
81 | */ |
||
82 | protected function dispatch(DomainEventInterface $event) |
||
86 | |||
87 | /** |
||
88 | * @param DomainEventSubscriberInterface $subscriber |
||
89 | */ |
||
90 | protected function addSubscriber(DomainEventSubscriberInterface $subscriber) |
||
94 | |||
95 | /** |
||
96 | * @param EventBus $eventBus |
||
97 | */ |
||
98 | protected function setEventBus(EventBus $eventBus) |
||
102 | |||
103 | /** |
||
104 | * @return EventBus |
||
105 | */ |
||
106 | protected function getEventBus() |
||
110 | } |
||
111 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: