MediaWiki REL1_36
|
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, plus any handlers added using register(). | |
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 | $dynamicHandlers = [] |
Hooks and their callbacks registered through $this->register() | |
array | $handlersByName = [] |
handler name and their handler objects | |
int | $nextScopedRegisterId = 0 |
The next ID to be used by scopedRegister() | |
ObjectFactory | $objectFactory |
HookRegistry | $registry |
array | $tombstones = [] |
Tombstone count by hook name. | |
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 327 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 |
MWException | If not in testing mode. |
Definition at line 187 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::emitDeprecationWarnings | ( | ) |
Will log a deprecation warning if:
Definition at line 487 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.
This does not include handlers registered dynamically using register(), nor does it include hooks registered via the old mechanism using $wgHooks.
string | $hook | Name of the hook |
array | $options | Handler options, which may include:
|
Definition at line 441 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getLegacyHandlers | ( | string | $hook | ) |
Get all handlers for legacy hooks system, plus any handlers added using register().
string | $hook | Name of hook |
Definition at line 396 of file HookContainer.php.
References $keys.
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 348 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 252 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 372 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.
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 125 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 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 212 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.