mockObject = NULL; $this->adhocHooks = array(); } /** * Use a unit-testing mock object to handle hook invocations * e.g. hook_civicrm_foo === $mockObject->foo() * @param object $mockObject */ public function setMock($mockObject) { $this->mockObject = $mockObject; } /** * Register a piece of code to run when invoking a hook * @param string $hook hook name, e.g civicrm_pre * @param array $callable function to call ie array(class, method) * eg. array($this, mymethod) */ public function setHook($hook, $callable) { $this->adhocHooks[$hook] = $callable; } /** *Invoke hooks * * @param int $numParams Number of parameters to pass to the hook * @param mixed $arg1 parameter to be passed to the hook * @param mixed $arg2 parameter to be passed to the hook * @param mixed $arg3 parameter to be passed to the hook * @param mixed $arg4 parameter to be passed to the hook * @param mixed $arg5 parameter to be passed to the hook * @param mixed $arg6 parameter to be passed to the hook * @param string $fnSuffix function suffix, this is effectively the hook name * * @return mixed */ /** * @param int $numParams * @param mixed $arg1 * @param mixed $arg2 * @param mixed $arg3 * @param mixed $arg4 * @param mixed $arg5 * @param mixed $arg6 * @param string $fnSuffix * * @return mixed */ function invoke($numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, $fnSuffix) { $params = array( &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6); if ($this->civiModules === NULL) { $this->civiModules = array(); $this->requireCiviModules($this->civiModules); } $this->runHooks($this->civiModules, $fnSuffix, $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); if ($this->mockObject && is_callable(array($this->mockObject, $fnSuffix))) { call_user_func(array($this->mockObject, $fnSuffix), $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); } if (!empty($this->adhocHooks[$fnSuffix])) { call_user_func_array($this->adhocHooks[$fnSuffix], $params ); } } }