ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
Public Member Functions | Private Attributes
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.

37  {
38  $this->context = $context;
39  $this->currentHook = array();
40  $this->hooks = array();
41  }

Member Function Documentation

__get (   $key)

Getter

Definition at line 116 of file Hooks.php.

117  {
118  switch ($key)
119  {
120  case "currentHook": return end($this->currentHook);
121  }
122  throw new \Exception("Cannot access attribute {$key}");
123  }
isInHook (   $hookName)
Parameters
string$hookName
Returns
boolean Check if $hookName is treating

Definition at line 94 of file Hooks.php.

95  {
96  foreach ($this->currentHook as $i)
97  if ($i->hookName == $hookName)
98  return true;
99  return false;
100  }
loadHooks (   $hookEntities)
Parameters
array(Entity) $module_hookEntities entities to load Reload hooks from entities

Definition at line 106 of file Hooks.php.

107  {
108  $this->hooks = array();
109  foreach ($hookEntities as $i)
110  $this->hooks[$i->hookName][] = (int) $i->module_id;
111  }
register (   $module,
  $hookName 
)
Parameters
\Tool\AModule$module
string$hooknameAttach 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.

51  {
53  throw new \Exception("You can only register hooks while installing");
54  if (!isset($this->hooks[$hookName]))
55  $this->hooks[$hookName] = array();
56  $this->hooks[$hookName][] = $module->entity->id;
57  $moduleHook = new \Entity\ModuleHook();
58  $moduleHook->module_id = $module->entity->id;
59  $moduleHook->hookName = $hookName;
60  $moduleHook->hookPosition = 10;
61  $moduleHook->save();
62  }
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.

71  {
72  if (empty($this->hooks[$hookName]))
73  return 0;
74  $hookEvent = new HookEvent($hookName, $this->context, $params);
75  array_push($this->currentHook, $hookEvent);
76  $result = 0;
77  foreach ($this->hooks[$hookName] as $module_id)
78  {
79  $module = $this->context->moduleManager->getModuleFromId($module_id);
80  if (!$module)
81  continue;
82  $module->doAction($hookEvent);
83  $result++;
84  }
85  array_pop($this->currentHook);
86  return $result;
87  }

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: