*/
static public function callHook($hook, $args = array(), $app = 'horde')
{
- $error = false;
- $hook_class = $app . '_Hooks';
-
- if (empty(self::$_hooksLoaded[$app]) &&
- !class_exists($hook_class, false)) {
- try {
- self::loadConfiguration('hooks.php', null, $app);
- } catch (Horde_Exception $e) {}
- self::$_hooksLoaded[$app] = true;
- }
-
- if (!class_exists($hook_class, false) ||
- !($hook_ob = new $hook_class) ||
- !method_exists($hook_ob, $hook)) {
+ if (!self::hookExists($hook, $app)) {
throw new Horde_Exception_HookNotSet();
}
+ $hook_class = $app . '_Hooks';
+ $hook_ob = new $hook_class;
try {
self::logMessage(sprintf('Hook %s in application %s called.', $hook, $app), 'DEBUG');
return call_user_func_array(array($hook_ob, $hook), $args);
}
/**
+ * Returns whether a hook exists.
+ *
+ * Use this if you have to call a hook many times and expect the hook to
+ * not exist.
+ *
+ * @param string $hook The function to call.
+ * @param string $app The hook application.
+ *
+ * @return boolean True if the hook exists.
+ */
+ static public function hookExists($hook, $app = 'horde')
+ {
+ $hook_class = $app . '_Hooks';
+
+ if (!isset(self::$_hooksLoaded[$app])) {
+ self::$_hooksLoaded[$app] = false;
+ if (!class_exists($hook_class, false)) {
+ try {
+ self::loadConfiguration('hooks.php', null, $app);
+ self::$_hooksLoaded[$app] = array();
+ } catch (Horde_Exception $e) {}
+ }
+ }
+
+ if (self::$_hooksLoaded[$app] === false) {
+ return false;
+ }
+
+ if (!isset(self::$_hooksLoaded[$app][$hook])) {
+ self::$_hooksLoaded[$app][$hook] =
+ class_exists($hook_class, false) &&
+ ($hook_ob = new $hook_class) &&
+ method_exists($hook_ob, $hook);
+ }
+
+ return self::$_hooksLoaded[$app][$hook];
+ }
+
+ /**
* Utility function to send redirect headers to browser, handling any
* browser quirks.
*
*/
public function getValue($attribute)
{
- if (isset($this->attributes[$attribute])) {
+ if (isset($this->attributes[$attribute]) &&
+ Horde::hookExists('decode_attribute', 'turba')) {
try {
return Horde::callHook('decode_attribute', array($attribute, $this->attributes[$attribute]), 'turba');
- } catch (Horde_Exception_HookNotSet $e) {
} catch (Turba_Exception $e) {}
}
*/
function setValue($attribute, $value)
{
- try {
- $value = Horde::callHook('encode_attribute', array($attribute, $value, isset($this->attributes[$attribute]) ? $this->attributes[$attribute] : null, $this), 'turba');
- } catch (Horde_Exception_HookNotSet $e) {
- } catch (Turba_Exception $e) {}
+ if (Horde::hookExists('encode_attribute', 'turba')) {
+ try {
+ $value = Horde::callHook('encode_attribute', array($attribute, $value, isset($this->attributes[$attribute]) ? $this->attributes[$attribute] : null, $this), 'turba');
+ } catch (Turba_Exception $e) {}
+ }
if (isset($this->driver->map[$attribute]) &&
is_array($this->driver->map[$attribute]) &&
!isset($this->driver->map[$attribute]['attribute'])) {
- return false;
+ return;
}
$this->attributes[$attribute] = $value;
- return true;
+ return;
}
/**