* ProtectedHookAccessorTrait provides protected getHookContainer() and getHookRunner() methods, getting them from the global service container. The point of this is to ease migration to DI by ensuring that call sites ask their local friendly base class rather than getting a HookRunner from the service container directly. * Migrate ChangesList and subclasses from Hooks::run() to the new system, as a pilot for full migration. Change-Id: Ic2d408fdb108087d81d0981aa670b35e0a6bb0ce
35 lines
926 B
PHP
35 lines
926 B
PHP
<?php
|
|
|
|
namespace MediaWiki\HookContainer;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* This trait provides an implementation of getHookContainer() and
|
|
* getHookRunner() for classes that do not use dependency injection. Its
|
|
* purpose is to provide a consistent API which can easily be maintained
|
|
* after the class has been migrated to dependency injection.
|
|
*/
|
|
trait ProtectedHookAccessorTrait {
|
|
/**
|
|
* Get a HookContainer, for running extension hooks or for hook metadata.
|
|
*
|
|
* @since 1.35
|
|
* @return HookContainer
|
|
*/
|
|
protected function getHookContainer() {
|
|
return MediaWikiServices::getInstance()->getHookContainer();
|
|
}
|
|
|
|
/**
|
|
* Get a HookRunner for running core hooks.
|
|
*
|
|
* @internal This is for use by core only. Hook interfaces may be removed
|
|
* without notice.
|
|
* @since 1.35
|
|
* @return HookRunner
|
|
*/
|
|
protected function getHookRunner() {
|
|
return new HookRunner( $this->getHookContainer() );
|
|
}
|
|
}
|