All Data Structures Namespaces Files Functions Variables
Hooks Class Reference

## Public Member Functions

| __construct (&$context)
| register ($module, $hookName)
| trigger ($hookName, $params=null)
| isInHook ($hookName)
| loadHooks ($hookEntities)
| __get ($key)

## Private Attributes

| $context
| $hooks
| $currentHook

## Detailed Description

Allow user to manage hooks

Definition at line 8 of file Hooks.php.

## Constructor & Destructor Documentation

__construct | ( | & | $context | ) |

ctor. Initialize context for having them passed to hook as parameter

Definition at line 36 of file Hooks.php.

{
$this->context = $context;
$this->currentHook = array();
$this->hooks = array();
}
Tools\Hooks\$context
$context
Definition: Hooks.php:15

## Member Function Documentation

__get | ( |  | $key | ) |

Getter

Definition at line 116 of file Hooks.php.

{
switch ($key)
{
case "currentHook": return end($this->currentHook);
}
throw new \Exception("Cannot access attribute {$key}");
}

isInHook | ( |  | $hookName | ) |

Parameters

  string | $hookName |

Returns
  boolean Check if $hookName is treating

Definition at line 94 of file Hooks.php.

{
foreach ($this->currentHook as $i)
if ($i->hookName == $hookName)
return true;
return false;
}

loadHooks | ( |  | $hookEntities | ) |

Parameters

  array( | Entity) $module_hookEntities entities to load Reload hooks from entities

Definition at line 106 of file Hooks.php.

{
$this->hooks = array();
foreach ($hookEntities as $i)
$this->hooks[$i->hookName][] = (int) $i->module_id;
}

register | ( |  | $module,
|  |  | $hookName
| ) |  |

Parameters

  \Tool\AModule | $module |
  string | $hookname | Attach module $module to $hookName Can only be called while installing the module. When fired, the AModule::doAction($hookName, $context) function will be called.

Definition at line 50 of file Hooks.php.

{
if (!\Tools\ModuleManager::isInstalling())
throw new \Exception("You can only register hooks while installing");
if (!isset($this->hooks[$hookName]))
$this->hooks[$hookName] = array();
$this->hooks[$hookName][] = $module->entity->id;
$moduleHook = new \Entity\ModuleHook();
$moduleHook->module_id = $module->entity->id;
$moduleHook->hookName = $hookName;
$moduleHook->hookPosition = 10;
$moduleHook->save();
}
Tools
Definition: AController.php:3
Tools\ModuleManager\isInstalling
static isInstalling()
Definition: ModuleManager.php:167

trigger | ( |  | $hookName,
|  |  | $params = `null`
| ) |  |

Parameters

  string | $hookName |

Returns
  number of modules successfully reached fire the hook hookName call the AModule::doAction($hookEvent) function for each attached modules

Definition at line 70 of file Hooks.php.

{
if (empty($this->hooks[$hookName]))
return 0;
$hookEvent = new HookEvent($hookName, $this->context, $params);
array_push($this->currentHook, $hookEvent);
$result = 0;
foreach ($this->hooks[$hookName] as $module_id)
{
$module = $this->context->moduleManager->getModuleFromId($module_id);
if (!$module)
continue;
$module->doAction($hookEvent);
$result++;
}
array_pop($this->currentHook);
return $result;
}

## Field Documentation

Tools Context $context

private

/core/tools/Context.php Contains website's informations

Definition at line 15 of file Hooks.php.

Tools HookEvent $currentHook

private

Contains current trigerred event

get current hook event

Definition at line 26 of file Hooks.php.

$hooks

private

Definition at line 20 of file Hooks.php.

The documentation for this class was generated from the following file:

- core/tools/Hooks.php