Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core\hook\manager Class Reference
Inheritance diagram for core\hook\manager:
Psr\EventDispatcher\EventDispatcherInterface Psr\EventDispatcher\ListenerProviderInterface

Public Member Functions

 dispatch (object $event)
 Provide all relevant listeners with an event to process.
 
 get_all_callbacks ()
 Returns list of all callbacks found in db/hooks.php files.
 
 get_callbacks_for_hook (string $hookclassname)
 Returns list of callbacks for given hook name.
 
 get_hooks_deprecating_plugin_callback (string $plugincallback)
 If the plugin callback from lib.php is deprecated by any hooks, return the hooks' classnames.
 
 get_hooks_with_callbacks ()
 Returns the list of Hook class names that have registered callbacks.
 
 getListenersForEvent (object $event)
 Get the list of listeners for the specified event.
 
 is_deprecated_plugin_callback (string $plugincallback)
 Is the plugin callback from lib.php deprecated by any hook?
 
 is_deprecating_hook_present (string $component, string $plugincallback)
 Is there a hook callback in component that deprecates given lib.php plugin callback?
 
 phpunit_redirect_hook (string $hookname, callable $callback)
 Override hook callbacks for testing purposes.
 
 phpunit_stop_redirections ()
 Cancel all redirections of hook callbacks.
 

Static Public Member Functions

static discover_known_hooks ()
 Returns list of hooks discovered through hook namespaces or discovery agents.
 
static get_instance ()
 Factory method, returns instance of manager that serves as hook dispatcher and callback provider.
 
static get_replaced_callbacks (string $hookclassname)
 Get the list of callbacks that the given hook class replaces (if any).
 
static phpunit_get_instance (array $componentfiles)
 Factory method for testing of hook manager in PHPUnit tests.
 

Member Function Documentation

◆ discover_known_hooks()

static core\hook\manager::discover_known_hooks ( )
static

Returns list of hooks discovered through hook namespaces or discovery agents.

The hooks overview page includes also all other classes that are referenced in callback registrations in db/hooks.php files, those are not included here.

Return values
arrayhook class names

◆ dispatch()

core\hook\manager::dispatch ( object $event)

Provide all relevant listeners with an event to process.

Parameters
object$eventThe object to process (aka hook).
Return values
objectThe Event that was passed, now modified by listeners.

Implements Psr\EventDispatcher\EventDispatcherInterface.

◆ get_all_callbacks()

core\hook\manager::get_all_callbacks ( )

Returns list of all callbacks found in db/hooks.php files.

Return values
iterable

◆ get_callbacks_for_hook()

core\hook\manager::get_callbacks_for_hook ( string $hookclassname)

Returns list of callbacks for given hook name.

NOTE: this is the "Listener Provider" described in PSR-14, instead of instance parameter it uses real PHP class names.

Parameters
string$hookclassnamePHP class name of hook
Return values
arraylist of callback definitions

◆ get_hooks_deprecating_plugin_callback()

core\hook\manager::get_hooks_deprecating_plugin_callback ( string $plugincallback)

If the plugin callback from lib.php is deprecated by any hooks, return the hooks' classnames.

Parameters
string$plugincallbackshort callback name without the component prefix
Return values
?array

◆ get_hooks_with_callbacks()

core\hook\manager::get_hooks_with_callbacks ( )

Returns the list of Hook class names that have registered callbacks.

Return values
array

◆ get_instance()

static core\hook\manager::get_instance ( )
static

Factory method, returns instance of manager that serves as hook dispatcher and callback provider.

Return values
self

◆ get_replaced_callbacks()

static core\hook\manager::get_replaced_callbacks ( string $hookclassname)
static

Get the list of callbacks that the given hook class replaces (if any).

Parameters
string$hookclassname
Return values
array

◆ getListenersForEvent()

core\hook\manager::getListenersForEvent ( object $event)

Get the list of listeners for the specified event.

Parameters
object$eventThe object being listened to (aka hook).
Return values
iterable<callable>An iterable (array, iterator, or generator) of callables. Each callable MUST be type-compatible with $event. Please note that in Moodle the callable must be a string.

Implements Psr\EventDispatcher\ListenerProviderInterface.

◆ is_deprecated_plugin_callback()

core\hook\manager::is_deprecated_plugin_callback ( string $plugincallback)

Is the plugin callback from lib.php deprecated by any hook?

Parameters
string$plugincallbackshort callback name without the component prefix
Return values
bool
Deprecated
in favour of get_hooks_deprecating_plugin_callback since Moodle 4.4.
Todo
Remove in Moodle 4.8 (MDL-80327).

◆ is_deprecating_hook_present()

core\hook\manager::is_deprecating_hook_present ( string $component,
string $plugincallback )

Is there a hook callback in component that deprecates given lib.php plugin callback?

NOTE: if there is both hook and deprecated callback then we ignore the old callback to allow compatibility of contrib plugins with multiple Moodle branches.

Parameters
string$component
string$plugincallbackshort callback name without the component prefix
Return values
bool

◆ phpunit_get_instance()

static core\hook\manager::phpunit_get_instance ( array $componentfiles)
static

Factory method for testing of hook manager in PHPUnit tests.

Please note that the result of this method should typically be passed to core\di\set().

Parameters
array$componentfileslist of hook callback files for each component.
Return values
self

◆ phpunit_redirect_hook()

core\hook\manager::phpunit_redirect_hook ( string $hookname,
callable $callback )

Override hook callbacks for testing purposes.

Parameters
string$hookname
callable$callback

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