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  }

Member Function Documentation

__get (   $key)

Getter

Definition at line 108 of file Hooks.php.

109  {
110  switch ($key)
111  {
112  case "currentHook": return end($this->currentHook);
113  }
114  throw new \Exception("Cannot access attribute {$key}");
115  }
isInHook (   $hookName)
Parameters
string$hookName
Returns
boolean Check if $hookName is treating

Definition at line 86 of file Hooks.php.

87  {
88  foreach ($this->currentHook as $i)
89  if ($i->hookName == $hookName)
90  return true;
91  return false;
92  }
loadHooks (   $hookEntities)
Parameters
array(Entity) $module_hookEntities entities to load Reload hooks from entities

Definition at line 98 of file Hooks.php.

99  {
100  $this->hooks = array();
101  foreach ($hookEntities as $i)
102  $this->hooks[$i->hookName][] = (int) $i->module_id;
103  }
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 49 of file Hooks.php.

50  {
51  if (!\Tools\ModuleManager::isInstalling())
52  throw new \Exception("You can only register hooks while installing");
53  //TODO@2
54  }
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 62 of file Hooks.php.

63  {
64  if (empty($this->hooks[$hookName]))
65  return 0;
66  $hookEvent = new HookEvent($hookName, $this->context, $params);
67  array_push($this->currentHook, $hookEvent);
68  $result = 0;
69  foreach ($this->hooks[$hookName] as $module_id)
70  {
71  $module = $this->context->moduleManager->getModuleFromId($module_id);
72  if (!$module)
73  continue;
74  $module->doAction($hookEvent);
75  $result++;
76  }
77  array_pop($this->currentHook);
78  return $result;
79  }

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: