Jump to content

Recommended Posts

Hooks ClicShopping\OM\Hooks

 

Introduction

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 ClicShopping\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 ClicShopping\OM\Hooks;

$CLICSHOPPING_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.
Hooks::call()

// no output expected
$CLICSHOPPING_Hooks->call('Account', 'Logout');

Parameters

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
Hooks::output()

// concatenated string output of all hooks executed
echo $CLICSHOPPING_Hooks->output('Orders', 'Page', null, 'display')

Parameters

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 ClicShopping\OM\Registry;

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

$CLICSHOPPING_Hooks->watch('Session', 'Recreated', 'execute', function($parameters) {
    ....
});

 

Link to post
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use