HookManager View code

A class to manage hooks, and to call hook handlers.

This class is capable of managing a flexible list of hooks, registering handlers for those hooks, and calling the handlers and/or related events.

package

CMS

license

GPL

since 2.2
author

Robert Campbell calguy1000@gmail.com

Methods

add_hook(string $name, callable $callable, integer $priority = self::PRIORITY_NORMAL) 

Add a handler to a hook

static

Arguments

string $name

The hook name. If the hook does not already exist, it is added.

callable $callable

A callable function, or a string representing a callable function. Closures are also supported.

integer $priority

The priority of the handler.

in_hook(null|string $name = null) : boolean

Test if we are currently handling a hook or not.

static

Arguments

null|string $name

The hook name to test for. If null is provided, the system will return true if any hook is being processed.

Response

boolean

do_hook() : mixed

Trigger a hook, progressively altering the value of the input.

static

This method accepts variable arguments. The first argument (required) is the name of the hook to execute. Further arguments will be passed to the various handlers.

Response

mixed

The output of this method depends on the hook.

do_hook_accumulate() : array

Trigger a hook, accumulating the results of each hook handler into an array.

static

This method accepts variable arguments. The first argument (required) is the name of the hook to execute. Further arguments will be passed to the various handlers.

Response

array

Constants

High priority handler

PRIORITY_HIGH

Indicates a normal priority handler

PRIORITY_NORMAL

Indicates a low priority handler

PRIORITY_LOW