*
* @param string $eventName The name of the event to dispatch. The name of
* the event is the name of the method that is invoked on listeners.
- * @param Event|null $event The event to pass to the event handlers/listeners
- * If not supplied, an empty Event instance is created
- *
- * @return Event
+ * @param object|null $event The event to pass to the event handlers/listeners
+ * The dispatcher accepts any kind of event-object.
+ * Events defined by CiviCRM-core are usually based on `GenericHookEvent`.
+ * If $event is a null, then an empty `GenericHookEvent` is created.
+ * @return object
+ * The final event object.
*/
public function dispatch($eventName, $event = NULL);
}
}
+ /**
+ * This checks whether Civi's dispatcher can be used as a backend for
+ * routing other event-objects (as in PSR-14).
+ */
+ public function testBasicEventObject(): void {
+ $d = new CiviEventDispatcher(\Civi::container());
+ $count = 0;
+ $d->addListener('testBasicEventObject', function($e) use (&$count) {
+ $this->assertTrue(is_object($e));
+ $count += $e->number;
+ });
+ $d->dispatch('testBasicEventObject', (object) ['number' => 100]);
+ $d->dispatch('testBasicEventObject', (object) ['number' => 200]);
+ $this->assertEquals(300, $count, '100 + 200 = 300.');
+ }
+
}