MediaWiki REL1_40
|
HookContainer class. More...
Inherits SalvageableService.
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. | |
getHookNames () | |
Returns the names of all hooks that have at least one handler registered. | |
getLegacyHandlers (string $hook) | |
Get all handlers for legacy hooks system, plus any handlers added using register(). | |
getRegisteredHooks () | |
Returns the names of all hooks that have handlers registered. | |
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. | |
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.
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 519 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 473 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::getHookNames | ( | ) |
Returns the names of all hooks that have at least one handler registered.
Definition at line 435 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 397 of file HookContainer.php.
References $keys.
MediaWiki\HookContainer\HookContainer::getRegisteredHooks | ( | ) |
Returns the names of all hooks that have handlers registered.
Note that this may include hook handlers that have been disabled using clear().
Definition at line 452 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 348 of file HookContainer.php.
MediaWiki\HookContainer\HookContainer::register | ( | string | $hook, |
$callback ) |
Attach an event handler to a given hook.
string | $hook | Name of hook |
mixed | $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.