Category:Hook System

From web2Project.net

Jump to: navigation, search

Available Since: v1.1 (September 2009) - Calendar, Cron, Search

Explanation

This is a list of hooks available within the web2project system. Each of these hooks is defined as a public method on the specific class. Therefore, it can be called by any code within the system which can instantiate the class.

Example

One such example of programmatically calling each of the active hooks within the system can be found in ./queuescanner.php (the code below is based on r420).

  $AppUI = new CAppUI;
  $AppUI->setUserLocale();
  $moduleList = $AppUI->getLoadableModuleList();
  foreach ($moduleList as $module) {
    include_once ($AppUI->getModuleClass($module['mod_directory']));
    $object = new $module['mod_main_class']();
    if (method_exists($object, 'hook_cron')) {
      $object->hook_cron();
    }
  }

To be specific, this code gets a list of all active modules in the system and loops over them. During the loop, this attempts to instantiate an object of that class and checks the object for the 'hook_cron' method. If the method exists, the system calls it. In this particular example, the results of calling the hook are not processed in any way. For sanity's sake, a hook should return FALSE if an error occurred and TRUE or the result if the method executed successfully.

The primary benefit of this implementation is that as additional modules (Core or Add On) are added to the system and activated, there's no further registration or configuration process. If the class implements the requested hook, it's automatically added for process. If the class does not implement the hook, it is skipped as expected.

While there may be other drawbacks, the primary is the memory footprint required. If the underlying classes or methods are large or complex, it's possible that PHP's memory footprint could become quite large.

Articles in category "Hook System"

There are 3 articles in this category.

C

S