\Orpheus\HookHook

The Hook class

This class is used by the core to trigger event with custom callbacks.

Summary

Methods
Properties
Constants
registerHook()
triggerHook()
create()
register()
trigger()
No public properties found
No constants found
__construct()
slug()
$hooks
$name
$callbacks
N/A
No private methods found
No private properties found
N/A

Properties

$hooks

$hooks : array

The registered hooks

Type

array

$name

$name : string

The name of this hook

Type

string

$callbacks

$callbacks : array

The registered callback for this hook

Type

array

Methods

registerHook()

registerHook(callback  $callback) : \Orpheus\Hook\Hook

Register a new callback for this hook.

Parameters

callback $callback

A callback.

Throws

\Exception

Returns

\Orpheus\Hook\Hook

triggerHook()

triggerHook(array  $params = NULL) : mixed

Trigger this hook.

Parameters

array $params

Params sent to the callback.

Returns

mixed —

The first param as result.

create()

create(string  $name) : \Orpheus\Hook\Hook

Create new Hook

Parameters

string $name

The new hook name.

Returns

\Orpheus\Hook\Hook

The new hook.

register()

register(string  $name, callback  $callback) : \Orpheus\Hook\Hook

Register a callback

Parameters

string $name

The hook name.

callback $callback

The new callback.

Throws

\Exception

Returns

\Orpheus\Hook\Hook

Add the callback to those of the hook.

trigger()

trigger(string  $name, boolean  $silent = false) : \Orpheus\Hook\The

Trigger a hook by name

Parameters

string $name

The hook name.

boolean $silent

Make it silent, no exception thrown. Default value is false.

Returns

\Orpheus\Hook\The —

triggerHook() result, usually the first parameter.

Trigger the hook named $name. e.g trigger('MyHook', true, $parameter1); trigger('MyHook', $parameter1, $parameter2); We advise to always provide $silent parameters if you pass additional parameters to the callback

__construct()

__construct(  $name) 

Constructor

Parameters

$name

The name of the new hook.

slug()

slug(string  $name) : string

Convert name to slug

Parameters

string $name

The hook name.

Returns

string —

The slug name.

Extract the slug of a hook name.