Hooks
in package
Hook management system that allows registering one or more functions to be called later
Tags
Table of Contents
Methods
- get_hook_registrations() : array<string|int, mixed>
- Retrieves all registered functions for a specific hook, sorted by order.
- run() : mixed
- Calls a group of registered functions, modifying and returning the first value (if present)
- set() : void
- Registers a function for a specific hook
Methods
get_hook_registrations()
Retrieves all registered functions for a specific hook, sorted by order.
public
static get_hook_registrations(string $name) : array<string|int, mixed>
Parameters
- $name : string
-
The name of the hook.
Return values
array<string|int, mixed> —An array of registered function metadata (['fn' => callable, 'order' => int, 'caller' => string]), or an empty array if the hook has no registrations.
run()
Calls a group of registered functions, modifying and returning the first value (if present)
public
static run(string $name, mixed ...$args) : mixed
When a hook is called, arguments are passed. The first argument will be the return value
Parameters
- $name : string
-
The name of the hook to run
- $args : mixed
-
Arguments to pass to the hook functions
Tags
Return values
mixed —The modified value after all hooks have processed it
set()
Registers a function for a specific hook
public
static set(string $name, callable $function[, int $order = 20 ]) : void
Parameters
- $name : string
-
The name of the hook
- $function : callable
-
The function to be called
- $order : int = 20
-
The execution order (lower numbers execute first)