f4php/hookmanager

HookManager is internal hooks core package for F4, a lightweight web development framework

Installs: 11

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/f4php/hookmanager

v0.0.1 2025-07-05 11:40 UTC

This package is auto-updated.

Last update: 2025-10-05 18:36:13 UTC


README

HookManager is an internal hooks core package for F4, a lightweight web development framework.

It is primarily used by F4 for collecting performance information to be displayed in debug mode.

Example Usage

HookManager uses a very simple API to register and invoke app-wide event handlers:

/*
 * The first step is to register a hook handler for an arbitrary hook name.
 * 
 * HookManager includes a set of hook names defined as constants looking like
 * HookManager::BEFORE_* and HookManager::AFTER_*, which are used by F4 internally.
 */
HookManager::addHook('hook name', function (array $context): bool {
    // do something useful
    return true;
});

// ...

/*
 * Once registered, hooks may be invoked (triggered) anywhere in the code.
 * 
 * This call will return an array composed of return values
 * produced by all registered handlers if present, or an empty
 * array otherwise.
 */
HookManager::triggerHook('hook name', ['context' => null]); // returns: [ 0 => true ]