mwstake/mediawiki-component-events

Mechanism for firing events

2.0.11 2024-04-19 14:33 UTC

README

This component allows you to emit notification events to consumers

Use in a MediaWiki extension

MediaWiki 1.35

  • Add "mwstake/mediawiki-component-events": "~1" to the require section of your composer.json file.

MediaWiki 1.39

  • Add "mwstake/mediawiki-component-events": "~2" to the require section of your composer.json file.

Register consumer

$GLOBALS['wgMWStakeNotificationEventConsumers'][] = [
	'class' => MyConsumer::class,
	'services' => [
		'UserFactory'
	]
];

Create Event

class MyEvent implements \MWStake\MediaWiki\Component\Events\INotificationEvent {
 ....
}

$event = new MyEvent( $user );

Emit Event

$notifier = MediaWikiServices::getInstance()->getService( 'MWStake.Notifier' );
$notifier->emit( $event );

// Will call MyConsumer::consume( $event )