MediaWiki REL1_35
|
HookContainer class. More...
Public Member Functions | |
__construct (HookRegistry $hookRegistry, ObjectFactory $objectFactory) | |
clear (string $hook) | |
Clear hooks registered via Hooks::register(). | |
emitDeprecationWarnings () | |
Will log a deprecation warning if: | |
getHandlers (string $hook, array $options=[]) | |
Return array of handler objects registered with given hook in the new system. | |
getLegacyHandlers (string $hook) | |
Get all handlers for legacy hooks system. | |
getOriginalHooksForTest () | |
Return hooks that were set before being potentially overridden by scopedRegister(). | |
isRegistered (string $hook) | |
Return whether hook has any handlers registered to it. | |
register (string $hook, $callback) | |
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, $callback, bool $replace=false) | |
Register hook and handler, allowing for easy removal. | |
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) | |
normalizeHandler ( $handler, string $hook) | |
Normalize/clean up format of argument passed as hook handler. | |
Private Attributes | |
array | $handlersByName = [] |
handler name and their handler objects | |
array | $legacyRegisteredHandlers = [] |
Hooks and their callbacks registered through $this->register() | |
int | $nextScopedRegisterId = 0 |
The next ID to be used by scopedRegister() | |
ObjectFactory | $objectFactory |
array | $originalHooks |
existing hook names and their handlers to restore between tests | |
HookRegistry | $registry |
HookContainer class.
Main class for managing hooks
Definition at line 44 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::__construct | ( | HookRegistry | $hookRegistry, |
ObjectFactory | $objectFactory | ||
) |
HookRegistry | $hookRegistry | |
ObjectFactory | $objectFactory |
Definition at line 68 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 318 of file HookContainer.php.
References $args, and wfDeprecated().
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 182 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::emitDeprecationWarnings | ( | ) |
Will log a deprecation warning if:
Definition at line 428 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getHandlers | ( | string | $hook, |
array | $options = [] |
||
) |
Return array of handler objects registered with given hook in the new system.
Definition at line 391 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getLegacyHandlers | ( | string | $hook | ) |
Get all handlers for legacy hooks system.
Definition at line 375 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getOriginalHooksForTest | ( | ) |
Return hooks that were set before being potentially overridden by scopedRegister().
For use in restoring registered hook handlers between tests.
MWException |
Definition at line 226 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 339 of file HookContainer.php.
|
private |
Normalize/clean up format of argument passed as hook handler.
array | callable | $handler | Executable handler function |
string | $hook | Hook name |
Definition at line 243 of file HookContainer.php.
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 352 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 120 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 |
MWException |
Definition at line 86 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 199 of file HookContainer.php.
|
private |
handler name and their handler objects
Definition at line 50 of file HookContainer.php.
|
private |
Hooks and their callbacks registered through $this->register()
Definition at line 47 of file HookContainer.php.
|
private |
The next ID to be used by scopedRegister()
Definition at line 59 of file HookContainer.php.
|
private |
Definition at line 56 of file HookContainer.php.
Referenced by MediaWiki\HookContainer\HookContainer\__construct().
|
private |
existing hook names and their handlers to restore between tests
Definition at line 62 of file HookContainer.php.
|
private |
Definition at line 53 of file HookContainer.php.