hook_manager View code

A class to add hook handlers and emit hooks of various types.

This class is capable of managing a flexible list of hooks, registering handlers for those hooks, and calling the handlers

package

CMS

license

GPL

since 2.3
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

emit() : mixed

Emit a hook, progressively altering the value of the input. i.e: a filter.

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.

emit_first_result() : mixed

Emit a hook, returning the first non empty value.

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.

This method will always pass the same input arguments to each hook handler.

Response

mixed

The output of this method depends on the hook.

emit_accumulate() : array

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

The data returned in the $params array will be appended to the output array.

Response

array

Mixed data, as it cannot be ascertained what data is passed back from handlers.

Constants

High priority handler

PRIORITY_HIGH

Indicates a normal priority handler

PRIORITY_NORMAL

Indicates a low priority handler

PRIORITY_LOW