mwstake/mediawiki-component-events

Mechanism for firing events

4.0.0 2025-04-02 17:51 UTC

README

This component allows you to emit notification events to consumers

Compatibility

  • 4.0.x -> MediaWiki 1.43
  • 3.0.x -> MediaWiki 1.39
  • 1.0.x -> MediaWiki 1.35

Use in a MediaWiki extension

Require this component in the composer.json of your extension:

{
	"require": {
		"mwstake/mediawiki-component-events": "~4"
	}
}

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 )