Hook manager implementing "Dispatcher" and "Event Provider" from PSR-14.
More...
|
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.
|
|
Hook manager implementing "Dispatcher" and "Event Provider" from PSR-14.
Due to class/method naming restrictions and collision with Moodle events the definitions from PSR-14 should be interpreted as:
- Event --> Hook
- Listener --> Hook callback
- Emitter --> Hook emitter
- Dispatcher --> Hook dispatcher - implemented in manager\dispatch()
- Listener Provider --> Hook callback provider - implemented in manager\get_callbacks_for_hook()
Note that technically any object can be a hook, but it is recommended to put all hook classes into component_name\hook namespaces and each hook should implement core\hook\described_hook interface.
- Author
- Petr Skoda
- Copyright
- 2022 Open LMS
- License
- https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ 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
-
◆ dispatch()
core\hook\manager::dispatch |
( |
object | $event | ) |
|
Provide all relevant listeners with an event to process.
- Parameters
-
object | $event | The object to process (aka hook). |
- Return values
-
object | The Event that was passed, now modified by listeners. |
◆ get_all_callbacks()
core\hook\manager::get_all_callbacks |
( |
| ) |
|
Returns list of all callbacks found in db/hooks.php files.
- Return values
-
◆ 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 | $hookclassname | PHP class name of hook |
- Return values
-
array | list 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
-
◆ 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
-
◆ getListenersForEvent()
core\hook\manager::getListenersForEvent |
( |
object | $event | ) |
|
Get the list of listeners for the specified event.
- Parameters
-
object | $event | The 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. |
◆ 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 | $plugincallback | short callback name without the component prefix |
- Return values
-
◆ 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 | $plugincallback | short callback name without the component prefix |
- Return values
-
◆ 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 | $componentfiles | list of hook callback files for each component. |
- Return values
-
◆ 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
-
◆ phpunit_stop_redirections()
core\hook\manager::phpunit_stop_redirections |
( |
| ) |
|
Cancel all redirections of hook callbacks.
- Return values
-
The documentation for this class was generated from the following file: