mwstake/mediawiki-component-events

Mechanism for firing events

3.0.5 2024-11-07 15:06 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 )