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": "MediaWiki\\Extension\\MyExtension\\Hooks::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.
This hook can be used to manipulate $wg…
configuration settings in test setups before any service is created, however the preferred place to do this is a registration callback function. 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.
Details
edit- $services: MediaWikiServices. See Dependency Injection for more information.