Manual:Hooks/MediaWikiServices

MediaWikiServices
Available from version 1.27.0
Called when the global MediaWikiServices singleton instance is initialized via MediaWikiServices::getInstance(), but no service was created yet.
Define function:
public static function onMediaWikiServices( MediaWikiServices $services ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"MediaWikiServices": "MyExtensionHooks::onMediaWikiServices"
	}
}
Called from: File(s): MediaWikiServices.php
Interface: MediaWikiServicesHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:MediaWikiServices extensions.


Extensions may use this to replace or decorate services, via the MediaWikiServices::redefineService() and MediaWikiServices::addServiceManipulator(). It can also be used to add new services, however the preferred way of doing that is the $wgServiceWiringFiles array.

While not originally intended, this hook can be used to manipulate $wg… configuration settings in test setups before any service is created. In the past, $wgExtensionFunctions and SetupAfterCache have been used for this purpose but those both risk that some service that uses the configuration settings about to be changed has already been instantiatied, and so the change has no effect. Using the MediaWikiServices hook avoids that.

DetailsEdit