wiki.techinc.nl/includes/HookContainer/GlobalHookRegistry.php
Tim Starling b3d762e148 Add HookRegistry
Add a HookRegistry interface and two concrete implementations,
representing HookContainer's view of its environment. This simplifies
creation of a HookContainer for testing.

Add MediaWikiTestCaseTrait::createHookContainer() which can be used
in most of the places that were previously creating mock hook
containers. It can also replace setTemporaryHook() in some cases.

Change-Id: I9ce15591dc40b3d717c203fa973141aa45a2500c
2020-05-13 11:51:02 +10:00

37 lines
830 B
PHP

<?php
namespace MediaWiki\HookContainer;
use ExtensionRegistry;
/**
* A HookRegistry which sources its data from dynamically changing sources:
* $wgHooks and an ExtensionRegistry.
*/
class GlobalHookRegistry implements HookRegistry {
/** @var ExtensionRegistry */
private $extensionRegistry;
/** @var DeprecatedHooks */
private $deprecatedHooks;
public function __construct(
ExtensionRegistry $extensionRegistry,
DeprecatedHooks $deprecatedHooks
) {
$this->extensionRegistry = $extensionRegistry;
$this->deprecatedHooks = $deprecatedHooks;
}
public function getGlobalHooks() {
global $wgHooks;
return $wgHooks;
}
public function getExtensionHooks() {
return $this->extensionRegistry->getAttribute( 'Hooks' ) ?? [];
}
public function getDeprecatedHooks() {
return $this->deprecatedHooks;
}
}