aboutsummaryrefslogtreecommitdiffstats
path: root/includes/DomainEvent/DomainEventSource.php
blob: d440705f528f516eb90aa16e836dbb29ba8e9425 (plain) (blame)
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
<?php
namespace MediaWiki\DomainEvent;

/**
 * Service object for registering listeners for domain events.
 *
 * @since 1.44
 * @unstable until 1.45
 */
interface DomainEventSource {

	/**
	 * Default options to apply when registering listeners.
	 * In the future, options may convey things like the listener priority or
	 * error handling.
	 */
	public const DEFAULT_LISTENER_OPTIONS = [];

	/**
	 * Add a listener that will be notified on events of the given type,
	 * triggered by a change to an entity on the local wiki.
	 *
	 * Listeners will be invoked after the transaction that produced the event
	 * was committed successfully. Delivery guarantees depend on the respective
	 * DomainEventDispatcher implementation.
	 *
	 * In a web request, listeners should be invoked after the response has been
	 * sent to the client, but still within the current process.
	 *
	 * Listeners may be invoked immediately if there is no active transaction
	 * round associated with the ConnectionProvider passed to
	 * DomainEventDispatcher::dispatch().
	 *
	 * Listeners should be implemented to be idempotent, that is, calling
	 * them multiple times with the same parameters should produce the same
	 * outcome.
	 *
	 * @param string $eventType
	 * @param callable $listener
	 * @param array $options Currently unused. In the future, $options may
	 * *        convey things like the listener priority or error handling.
	 */
	public function registerListener(
		string $eventType,
		$listener,
		array $options = self::DEFAULT_LISTENER_OPTIONS
	): void;

	/**
	 * Register the given subscriber to this event source. A subscriber
	 * is a way to bundle related listeners, typically by implementing them
	 * as methods on the subscriber object.
	 *
	 * If the subscriber is supplied as a spec array, instantiation and
	 * application may be deferred until one of the relevant events is
	 * triggered.
	 *
	 * @param DomainEventSubscriber|array $subscriber
	 * - object: a DomainEventSubscriber
	 * - array: An object spec suitable for use with ObjectFactory.
	 *          The array must use the key 'events' to specify which
	 *          events will trigger application of the subscriber.
	 */
	public function registerSubscriber( $subscriber ): void;

}