Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
EventBusRCFeedEngine | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
send | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\EventBus\Adapters\RCFeed; |
4 | |
5 | use MediaWiki\Deferred\DeferredUpdates; |
6 | use MediaWiki\Extension\EventBus\EventBus; |
7 | use MediaWiki\RCFeed\FormattedRCFeed; |
8 | |
9 | /** |
10 | * Emit a recent change notification via EventBus. |
11 | * |
12 | * The event's stream will be 'mediawiki.recentchange' as set |
13 | * in EventBusRCFeedFormatter::STREAM. wgEventStreams or wgEventServiceDefault |
14 | * specifies the destination event service for recentchange events. |
15 | * |
16 | * @example |
17 | * |
18 | * // Event Service MediaWiki config |
19 | * $wgEventServices = array( |
20 | * 'eventgate-example' => array( |
21 | * 'url' => 'http://eventgate-example.svc.example.org:4492/v1/events', |
22 | * 'timeout' => 60 |
23 | * ) |
24 | * ); |
25 | * |
26 | * // Event Stream Config managed by EventStreamConfig extension |
27 | * // per event stream configuration: |
28 | * $wgEventStreams = [ |
29 | * [ |
30 | * 'stream' => mediawiki.recentchange', |
31 | * 'destination_event_service' => 'eventgate-main' |
32 | * ], |
33 | * ... |
34 | * ]; |
35 | * |
36 | * // RCFeed configuration to use a defined Event Service instance. |
37 | * $wgRCFeeds['eventbus'] = array( |
38 | * 'class' => 'EventBusRCFeedEngine', |
39 | * 'formatter' => 'EventBusRCFeedFormatter', |
40 | * ); |
41 | */ |
42 | class EventBusRCFeedEngine extends FormattedRCFeed { |
43 | |
44 | /** |
45 | * @param array $feed is expected to contain 'eventServiceName', which will |
46 | * be looked up by EventBus in wgEventServices. |
47 | * @param string|array $line to send |
48 | * @return bool Success |
49 | * |
50 | * @see FormattedRCFeed::send |
51 | */ |
52 | public function send( array $feed, $line ) { |
53 | $eventBus = EventBus::getInstanceForStream( EventBusRCFeedFormatter::STREAM ); |
54 | DeferredUpdates::addCallableUpdate( |
55 | static function () use ( $eventBus, $line ) { |
56 | return $eventBus->send( $line ); |
57 | } |
58 | ); |
59 | |
60 | return true; |
61 | } |
62 | } |