/** * Run any handlers for the specified hook type. Output of the * handlers is concatenated and returned. Hooks are specified in * the `[Hooks]` section of each app's `conf/config.php` file, * like follows: * * [Hooks] * * myapp/newpost[] = search/add * myapp/newpost[] = twitter/posttweet * * Hooks may also be listed in the global `conf/config.php` in * the same format. */ public function hook($type, $data = array()) { $pos = strpos($type, '/'); if ($pos > 0) { $app = substr($type, 0, $pos); if (!isset(self::$_hooks_loaded[$app])) { $hooks = Appconf::get($app, 'Hooks'); if (is_array($hooks)) { self::$hooks = array_merge_recursive(self::$hooks, $hooks); } self::$_hooks_loaded[$app] = true; } } if (!isset(self::$hooks[$type])) { return false; } $out = ''; foreach (self::$hooks[$type] as $handler) { $out .= $this->run($handler, $data); } return $out; }
/** * Constructor method. */ public function __construct($hooks = array()) { if (defined('STDIN')) { $this->cli = true; } self::$hooks = $hooks; }