Online Merchant v2.4 Joli

Hooks OSC\OM\Hooks


Hooks allow action callouts to be thrown during an event to execute additional functionality. Hooks are not modules in the traditional sense of being able to be installed and configured; they are simply modular functions waiting to be executed on demand with no configuration or administration whatsoever.

For security reasons, hooks must be defined in their Apps metadata file otherwise they will not be made available for the framework to use.

Hooks are initialized by creating an instance of OSC\OM\Hooks and specifying the Site to call the hook action from. If no Site is passed, the Site that initialized the framework is used as default.

use OSC\OM\Hooks;

$OSCOM_Hooks = new Hooks();
Hooks() is automatically initialized on each page request and is available in the Registry as Hooks.

Action Callout

Throwing out an action callout is performed by specifying the group the action belongs to, the actual action name, and optionally a specific function to execute. There are two types of callouts that can be peformed:

Type Description
call() Executes the hooks and can return an array of results depending on the action.
output() Executes the hooks and returns the output as a string.
// no output expected
$OSCOM_Hooks->call('Account', 'Logout');


Hooks::call($group, $hook, $parameters, $action)
Parameter Value
$group The group the action call belongs to.
$hook The name of the action to call.
$parameters Any parameters to pass to the hooks.
$action The name of the hook function to execute. Default: execute
// concatenated string output of all hooks executed
echo $OSCOM_Hooks->output('Orders', 'Page', null, 'display')


Hooks::output($group, $hook, $parameters, $action)

The output() method shares the same function parameters as the call() class method.

A list of hook action callouts is available on the List of Hook Callouts page.

Runtime Watches

Runtime watches can be defined that execute when the hook is called. This differs from hooks defined in App metadata files as they are defined in-line and execute either an existing function or are defined with an anonymous function to execute:

use OSC\OM\Registry;

$OSCOM_Hooks = Registry::get('Hooks');

$OSCOM_Hooks->watch('Session', 'Recreated', 'execute', function($parameters) {