Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
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_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 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_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

◆ 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

◆ 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.

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
Return values
void

◆ phpunit_stop_redirections()

core\hook\manager::phpunit_stop_redirections ( )

Cancel all redirections of hook callbacks.

Return values
void

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