MediaWiki
master
|
HookContainer class. More...
Public Member Functions | |
__construct (HookRegistry $hookRegistry, ObjectFactory $objectFactory) | |
clear (string $hook) | |
Clear hooks registered via Hooks::register(). More... | |
emitDeprecationWarnings () | |
Will log a deprecation warning if: More... | |
getHandlers (string $hook, array $options=[]) | |
Return array of handler objects registered with given hook in the new system. More... | |
getLegacyHandlers (string $hook) | |
Get all handlers for legacy hooks system, plus any handlers added using register(). More... | |
isRegistered (string $hook) | |
Return whether hook has any handlers registered to it. More... | |
register (string $hook, $callback) | |
Attach an event handler to a given hook. More... | |
run (string $hook, array $args=[], array $options=[]) | |
Call registered hook functions through either the legacy $wgHooks or extension.json. More... | |
salvage (SalvageableService $other) | |
Salvage the state of HookContainer by retaining existing handler objects and hooks registered via HookContainer::register(). More... | |
scopedRegister (string $hook, $callback, bool $replace=false) | |
Register hook and handler, allowing for easy removal. More... | |
Private Member Functions | |
callLegacyHook (string $hook, $handler, array $args, array $options) | |
Run legacy hooks Hook can be: a function, an object, an array of $function and $data, an array of just a function, an array of object and method, or an array of object, method, and data (See hooks.txt for more details) More... | |
normalizeHandler ( $handler, string $hook) | |
Normalize/clean up format of argument passed as hook handler. More... | |
Private Attributes | |
array | $dynamicHandlers = [] |
Hooks and their callbacks registered through $this->register() More... | |
array | $handlersByName = [] |
handler name and their handler objects More... | |
int | $nextScopedRegisterId = 0 |
The next ID to be used by scopedRegister() More... | |
ObjectFactory | $objectFactory |
HookRegistry | $registry |
array | $tombstones = [] |
Tombstone count by hook name. More... | |
HookContainer class.
Main class for managing hooks
Definition at line 45 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::__construct | ( | HookRegistry | $hookRegistry, |
ObjectFactory | $objectFactory | ||
) |
HookRegistry | $hookRegistry | |
ObjectFactory | $objectFactory |
Definition at line 75 of file HookContainer.php.
References MediaWiki\HookContainer\HookContainer\$objectFactory.
|
private |
Run legacy hooks Hook can be: a function, an object, an array of $function and $data, an array of just a function, an array of object and method, or an array of object, method, and data (See hooks.txt for more details)
string | $hook | |
array | callable | $handler | The name of the hooks handler function |
array | $args | Arguments for hook handler function |
array | $options |
Definition at line 322 of file HookContainer.php.
References $args, and wfDeprecated().
Referenced by MediaWiki\HookContainer\HookContainer\run().
MediaWiki\HookContainer\HookContainer::clear | ( | string | $hook | ) |
Clear hooks registered via Hooks::register().
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 190 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::emitDeprecationWarnings | ( | ) |
Will log a deprecation warning if:
Definition at line 482 of file HookContainer.php.
References MWDebug\sendRawDeprecated().
MediaWiki\HookContainer\HookContainer::getHandlers | ( | string | $hook, |
array | $options = [] |
||
) |
Return array of handler objects registered with given hook in the new system.
This does not include handlers registered dynamically using register(), nor does it include hooks registered via the old mechanism using $wgHooks.
Definition at line 436 of file HookContainer.php.
Referenced by MediaWiki\HookContainer\HookContainer\run().
MediaWiki\HookContainer\HookContainer::getLegacyHandlers | ( | string | $hook | ) |
Get all handlers for legacy hooks system, plus any handlers added using register().
Definition at line 391 of file HookContainer.php.
References $keys.
Referenced by MediaWiki\HookContainer\HookContainer\isRegistered(), and MediaWiki\HookContainer\HookContainer\run().
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 343 of file HookContainer.php.
References MediaWiki\HookContainer\HookContainer\getLegacyHandlers().
|
private |
Normalize/clean up format of argument passed as hook handler.
array | callable | $handler | Executable handler function |
string | $hook | Hook name |
Definition at line 255 of file HookContainer.php.
Referenced by MediaWiki\HookContainer\HookContainer\run().
MediaWiki\HookContainer\HookContainer::register | ( | string | $hook, |
$callback | |||
) |
Attach an event handler to a given hook.
string | $hook | Name of hook |
callable | string | array | $callback | handler object to attach |
Definition at line 367 of file HookContainer.php.
References wfDeprecated().
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.
For hooks that are not abortable through a handler's return value, use runWithoutAbort() instead.
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 128 of file HookContainer.php.
References $args, MediaWiki\HookContainer\HookContainer\callLegacyHook(), MediaWiki\HookContainer\HookContainer\getHandlers(), MediaWiki\HookContainer\HookContainer\getLegacyHandlers(), MediaWiki\HookContainer\HookContainer\normalizeHandler(), and wfDeprecatedMsg().
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 |
MWException |
Definition at line 93 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::scopedRegister | ( | string | $hook, |
$callback, | |||
bool | $replace = false |
||
) |
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 | $callback | Handler object to attach |
bool | $replace | (optional) By default adds callback to handler array. Set true to remove all existing callbacks for the hook. |
Definition at line 215 of file HookContainer.php.
|
private |
Hooks and their callbacks registered through $this->register()
Definition at line 49 of file HookContainer.php.
|
private |
handler name and their handler objects
Definition at line 60 of file HookContainer.php.
|
private |
The next ID to be used by scopedRegister()
Definition at line 69 of file HookContainer.php.
|
private |
Definition at line 66 of file HookContainer.php.
Referenced by MediaWiki\HookContainer\HookContainer\__construct().
|
private |
Definition at line 63 of file HookContainer.php.
|
private |
Tombstone count by hook name.
Definition at line 54 of file HookContainer.php.