MIDDAG for Moodle

hook_manager implements hook_manager_interface

Lightweight Hook Manager (WordPress style).

Handles synchronous execution of filters and actions. Registration is handled by individual Extensions during boot.

Table of Contents

Interfaces

hook_manager_interface
Contract for the Hook Manager.

Properties

$actions  : array<string, array<int, array<string|int, mixed>>>
$filters  : array<string, array<int, array<string|int, mixed>>>

Methods

add_action()  : void
Register a new action callback.
add_filter()  : void
Register a new filter callback.
apply_filters()  : mixed
Apply all filter callbacks registered for a given tag.
do_action()  : void
Execute all action callbacks registered for a given tag.
has_action()  : bool
Check if any action has been registered for a hook.
reset()  : void
Clear all registered hooks. Essential for unit testing isolation.

Properties

$actions

private static array<string, array<int, array<string|int, mixed>>> $actions = []

Stores registered actions

$filters

private static array<string, array<int, array<string|int, mixed>>> $filters = []

Stores registered filters

Methods

add_action()

Register a new action callback.

public static add_action(string $tag, callable $function[, int $priority = 10 ][, int $args = 1 ]) : void
Parameters
$tag : string

The action name/identifier

$function : callable

The callback function

$priority : int = 10

Priority (lower number runs earlier)

$args : int = 1

Number of accepted arguments

add_filter()

Register a new filter callback.

public static add_filter(string $tag, callable $function[, int $priority = 10 ][, int $args = 1 ]) : void
Parameters
$tag : string

The filter name/identifier

$function : callable

The callback function

$priority : int = 10

Priority (lower number runs earlier)

$args : int = 1

Number of accepted arguments

apply_filters()

Apply all filter callbacks registered for a given tag.

public static apply_filters(string $tag, mixed $value, mixed ...$args) : mixed

Each callback receives the current value and must return a (possibly modified) value.

Parameters
$tag : string

The filter name

$value : mixed

The initial value to filter

$args : mixed

Additional arguments passed to the callbacks

Return values
mixed

The filtered value

do_action()

Execute all action callbacks registered for a given tag.

public static do_action(string $tag, mixed ...$args) : void

Unlike filters, actions do not return values.

Parameters
$tag : string

The action name

$args : mixed

Arguments passed to the callbacks

has_action()

Check if any action has been registered for a hook.

public static has_action(string $tag) : bool
Parameters
$tag : string
Return values
bool

reset()

Clear all registered hooks. Essential for unit testing isolation.

public static reset() : void

        
On this page

Search results