MediaWiki  1.23.15
Hooks Class Reference

Hooks class. More...

Static Public Member Functions

static clear ( $name)
 Clears hooks registered via Hooks::register(). More...
 
static getHandlers ( $name)
 Returns an array of all the event functions attached to a hook This combines functions registered via Hooks::register and with $wgHooks. More...
 
static isRegistered ( $name)
 Returns true if a hook has a function registered to it. More...
 
static register ( $name, $callback)
 Attach an event handler to a given hook. More...
 
static run ( $event, array $args=array(), $deprecatedVersion=null)
 Call hook functions defined in Hooks::register and $wgHooks. More...
 

Static Protected Attributes

static $handlers = array()
 Array of events mapped to an array of callbacks to be run when that event is triggered. More...
 

Detailed Description

Hooks class.

Used to supersede $wgHooks, because globals are EVIL.

Since
1.18

Definition at line 39 of file Hooks.php.

Member Function Documentation

◆ clear()

static Hooks::clear (   $name)
static

Clears hooks registered via Hooks::register().

Does not touch $wgHooks. This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.

Parameters
string$namethe name of the hook to clear.
Since
1.21
Exceptions
MWExceptionif not in testing mode.

Definition at line 72 of file Hooks.php.

References $name.

Referenced by PHPUnitMaintClass\finalSetup(), and HooksTest\setUp().

◆ getHandlers()

static Hooks::getHandlers (   $name)
static

Returns an array of all the event functions attached to a hook This combines functions registered via Hooks::register and with $wgHooks.

Since
1.18
Parameters
string$nameName of the hook
Returns
array

Definition at line 103 of file Hooks.php.

References $name, $wgHooks, array(), and global.

Referenced by ContentHandler\runLegacyHooks(), and HooksTest\testNewStyleHookInteraction().

◆ isRegistered()

static Hooks::isRegistered (   $name)
static

Returns true if a hook has a function registered to it.

The function may have been registered either via Hooks::register or in $wgHooks.

Since
1.18
Parameters
string$nameName of hook
Returns
bool True if the hook has a function registered to it

Definition at line 89 of file Hooks.php.

References $name, $wgHooks, and global.

Referenced by ContentHandler\runLegacyHooks(), and HooksTest\testNewStyleHookInteraction().

◆ register()

static Hooks::register (   $name,
  $callback 
)
static

Attach an event handler to a given hook.

Parameters
string$nameName of hook
mixed$callbackCallback function to attach
Since
1.18

Definition at line 55 of file Hooks.php.

References $name, and array().

Referenced by BenchmarkParse\execute(), PHPUnitMaintClass\finalSetup(), HooksTest\testFalseReturn(), HooksTest\testFatalError(), HooksTest\testNewStyleHookInteraction(), HooksTest\testNewStyleHooks(), ContentHandlerTest\testRunLegacyHooks(), and HooksTest\testUncallableFunction().

◆ run()

static Hooks::run (   $event,
array  $args = array(),
  $deprecatedVersion = null 
)
static

Call hook functions defined in Hooks::register and $wgHooks.

For a certain hook event, fetch the array of hook events 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.

Parameters
string$eventEvent name
array$argsArray of parameters passed to hook functions
string | null$deprecatedVersionOptionally, mark hook as deprecated with version number
Returns
bool True if no handler aborted the hook
Since
1.22 A hook function is not required to return a value for processing to continue. Not returning a value (or explicitly returning null) is equivalent to returning true.
Exceptions
MWException
FatalError

Definition at line 136 of file Hooks.php.

References $args, $retval, array(), as, wfDeprecated(), wfProfileIn(), and wfProfileOut().

Referenced by ApiMain\lacksSameOriginSecurity(), MWExceptionHandler\logException(), HooksTest\testFalseReturn(), HooksTest\testFatalError(), HooksTest\testNewStyleHookInteraction(), HooksTest\testNewStyleHooks(), HooksTest\testUncallableFunction(), and MediaWiki\tryNormaliseRedirect().

Member Data Documentation

◆ $handlers

Hooks::$handlers = array()
staticprotected

Array of events mapped to an array of callbacks to be run when that event is triggered.

Definition at line 45 of file Hooks.php.


The documentation for this class was generated from the following file: