MediaWiki master
|
HookContainer class. More...
Inherits SalvageableService.
Public Member Functions | |
__construct (HookRegistry $hookRegistry, ObjectFactory $objectFactory) | |
clear (string $hook) | |
Clear handlers of the given hook. | |
emitDeprecationWarnings () | |
For each hook handler of each hook, this will log a deprecation if: | |
getHandlerCallbacks (string $hook) | |
Get handler callbacks. | |
getHandlerDescriptions (string $hook) | |
Return the array of strings that describe the handler registered with the given hook. | |
getHookNames () | |
Returns the names of all hooks that have at least one handler registered. | |
isRegistered (string $hook) | |
Return whether hook has any handlers registered to it. | |
register (string $hook, $handler) | |
Attach an event handler to a given hook. | |
run (string $hook, array $args=[], array $options=[]) | |
Call registered hook functions through either the legacy $wgHooks or extension.json. | |
salvage (SalvageableService $other) | |
Salvage the state of HookContainer by retaining existing handler objects and hooks registered via HookContainer::register(). | |
scopedRegister (string $hook, $handler) | |
Register hook and handler, allowing for easy removal. | |
Public Attributes | |
const | NOOP = '*no-op*' |
HookContainer class.
Main class for managing hooks
Definition at line 57 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::__construct | ( | HookRegistry | $hookRegistry, |
ObjectFactory | $objectFactory ) |
HookRegistry | $hookRegistry | |
ObjectFactory | $objectFactory |
Definition at line 93 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::clear | ( | string | $hook | ) |
Clear handlers of the given hook.
This is intended for use while testing and will fail if MW_PHPUNIT_TEST and MW_PARSER_TEST are not defined.
string | $hook | Name of hook to clear |
Definition at line 189 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::emitDeprecationWarnings | ( | ) |
For each hook handler of each hook, this will log a deprecation if:
Definition at line 610 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getHandlerCallbacks | ( | string | $hook | ) |
Get handler callbacks.
string | $hook | Name of hook |
Definition at line 465 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getHandlerDescriptions | ( | string | $hook | ) |
Return the array of strings that describe the handler registered with the given hook.
string | $hook | Name of the hook |
Definition at line 547 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getHookNames | ( | ) |
Returns the names of all hooks that have at least one handler registered.
Definition at line 492 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::isRegistered | ( | string | $hook | ) |
Return whether hook has any handlers registered to it.
The function may have been registered via Hooks::register or in extension.json
string | $hook | Name of hook |
Definition at line 405 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::register | ( | string | $hook, |
$handler ) |
Attach an event handler to a given hook.
The handler should be given in one of the following forms:
1) A callable (string, array, or closure) 2) An extension hook handler spec in the form returned by HookRegistry::getExtensionHooks
Several other forms are supported for backwards compatibility, but should not be used when calling this method directly.
string | $hook | Name of hook |
string | array | callable | $handler | handler |
Definition at line 435 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::run | ( | string | $hook, |
array | $args = [], | ||
array | $options = [] ) |
Call registered hook functions through either the legacy $wgHooks or extension.json.
For the given hook, fetch the array of handler objects and process them. Determine the proper callback for each hook and then call the actual hook using the appropriate arguments. Finally, process the return value and return/throw accordingly.
string | $hook | Name of the hook |
array | $args | Arguments to pass to hook handler |
array | $options | options map:
|
UnexpectedValueException | if handlers return an invalid value |
Definition at line 142 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::salvage | ( | SalvageableService | $other | ) |
Salvage the state of HookContainer by retaining existing handler objects and hooks registered via HookContainer::register().
Necessary in the event that MediaWikiServices::resetGlobalInstance() is called after hooks have already been registered.
HookContainer | SalvageableService | $other | The object to salvage state from. $other be of type HookContainer |
Definition at line 110 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::scopedRegister | ( | string | $hook, |
$handler ) |
Register hook and handler, allowing for easy removal.
Intended for use in temporary registration e.g. testing
string | $hook | Name of hook |
callable | string | array | $handler | Handler to attach |
Definition at line 205 of file HookContainer.php.
const MediaWiki\HookContainer\HookContainer::NOOP = '*no-op*' |
Definition at line 60 of file HookContainer.php.