3 * Handles adding and dispatching events
6 * @subpackage Utilities
10 * Handles adding and dispatching events
13 * @subpackage Utilities
15 class Requests_Hooks implements Requests_Hooker {
17 * Registered callbacks for each hook
21 protected $hooks = array();
26 public function __construct() {
31 * Register a callback for a hook
33 * @param string $hook Hook name
34 * @param callback $callback Function/method to call on event
35 * @param int $priority Priority number. <0 is executed earlier, >0 is executed later
37 public function register($hook, $callback, $priority = 0) {
38 if (!isset($this->hooks[$hook])) {
39 $this->hooks[$hook] = array();
41 if (!isset($this->hooks[$hook][$priority])) {
42 $this->hooks[$hook][$priority] = array();
45 $this->hooks[$hook][$priority][] = $callback;
51 * @param string $hook Hook name
52 * @param array $parameters Parameters to pass to callbacks
53 * @return boolean Successfulness
55 public function dispatch($hook, $parameters = array()) {
56 if (empty($this->hooks[$hook])) {
60 foreach ($this->hooks[$hook] as $priority => $hooked) {
61 foreach ($hooked as $callback) {
62 call_user_func_array($callback, $parameters);