Add null Alarm driver.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 6 May 2010 16:36:48 +0000 (10:36 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 6 May 2010 16:38:26 +0000 (10:38 -0600)
Not sure if this is the right way of handling this, but Horde is
completely unusable without this for anybody who doesn't have a SQL
backend configured.

framework/Alarm/lib/Horde/Alarm.php
framework/Alarm/lib/Horde/Alarm/Null.php [new file with mode: 0644]
framework/Alarm/package.xml

index 083d6ac..78e2408 100644 (file)
@@ -52,7 +52,7 @@ abstract class Horde_Alarm
         $class = __CLASS__ . '_' . $driver;
 
         if (!class_exists($class)) {
-            throw new Horde_Alarm_Exception('Could not find driver.');
+            $class = __CLASS__ . '_Null';
         }
 
         $alarm = new $class($params);
diff --git a/framework/Alarm/lib/Horde/Alarm/Null.php b/framework/Alarm/lib/Horde/Alarm/Null.php
new file mode 100644 (file)
index 0000000..0c33721
--- /dev/null
@@ -0,0 +1,193 @@
+<?php
+/**
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @package Horde_Alarm
+ */
+
+/**
+ * Null Alarm driver.
+ *
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Horde_Alarm
+ */
+class Horde_Alarm_Null extends Horde_Alarm
+{
+    /**
+     * Returns a list of alarms from the backend.
+     *
+     * @param Horde_Date $time  The time when the alarms should be active.
+     * @param string $user      Return alarms for this user, all users if
+     *                          null, or global alarms if empty.
+     *
+     * @return array  A list of alarm hashes.
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _list($user, Horde_Date $time)
+    {
+        return array();
+    }
+
+    /**
+     * Returns an alarm hash from the backend.
+     *
+     * @param string $id    The alarm's unique id.
+     * @param string $user  The alarm's user
+     *
+     * @return array  An alarm hash.
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _get($id, $user)
+    {
+        return array();
+    }
+
+    /**
+     * Adds an alarm hash to the backend.
+     *
+     * @param array $alarm  An alarm hash.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _add(array $alarm)
+    {
+    }
+
+    /**
+     * Updates an alarm hash in the backend.
+     *
+     * @param array $alarm         An alarm hash.
+     * @param boolean $keepsnooze  Whether to keep the snooze value unchanged.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _update(array $alarm, $keepsnooze = false)
+    {
+    }
+
+    /**
+     * Updates internal alarm properties, i.e. properties not determined by
+     * the application setting the alarm.
+     *
+     * @param string $id       The alarm's unique id.
+     * @param string $user     The alarm's user
+     * @param array $internal  A hash with the internal data.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _internal($id, $user, array $internal)
+    {
+    }
+
+    /**
+     * Returns whether an alarm with the given id exists already.
+     *
+     * @param string $id    The alarm's unique id.
+     * @param string $user  The alarm's user
+     *
+     * @return boolean  True if the specified alarm exists.
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _exists($id, $user)
+    {
+        return false;
+    }
+
+    /**
+     * Delays (snoozes) an alarm for a certain period.
+     *
+     * @param string $id          The alarm's unique id.
+     * @param string $user        The alarm's user
+     * @param Horde_Date $snooze  The snooze time.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _snooze($id, $user, Horde_Date $snooze)
+    {
+    }
+
+    /**
+     * Returns whether an alarm is snoozed.
+     *
+     * @param string $id        The alarm's unique id.
+     * @param string $user      The alarm's user
+     * @param Horde_Date $time  The time when the alarm may be snoozed.
+     *
+     * @return boolean  True if the alarm is snoozed.
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _isSnoozed($id, $user, Horde_Date $time)
+    {
+        return false;
+    }
+
+    /**
+     * Dismisses an alarm.
+     *
+     * @param string $id          The alarm's unique id.
+     * @param string $user        The alarm's user
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _dismiss($id, $user)
+    {
+    }
+
+    /**
+     * Deletes an alarm from the backend.
+     *
+     * @param string $id    The alarm's unique id.
+     * @param string $user  The alarm's user. All users' alarms if null.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _delete($id, $user = null)
+    {
+    }
+
+    /**
+     * Garbage collects old alarms in the backend.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    protected function _gc()
+    {
+    }
+
+    /**
+     * Attempts to initialize the backend.
+     *
+     * @throws Horde_Alarm_Exception
+     */
+    public function initialize()
+    {
+    }
+
+    /**
+     * Converts a value from the driver's charset.
+     *
+     * @param mixed $value  Value to convert.
+     *
+     * @return mixed  Converted value.
+     */
+    protected function _fromDriver($value)
+    {
+        return $value;
+    }
+
+    /**
+     * Converts a value to the driver's charset.
+     *
+     * @param mixed $value  Value to convert.
+     *
+     * @return mixed  Converted value.
+     */
+    protected function _toDriver($value)
+    {
+        return $value;
+    }
+
+}
index a2158ba..ad2bd39 100644 (file)
@@ -33,6 +33,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <dir name="Horde">
      <dir name="Alarm">
       <file name="Exception.php" role="php" />
+      <file name="Null.php" role="php" />
       <file name="Object.php" role="php" />
       <file name="Sql.php" role="php" />
      </dir> <!-- /lib/Horde/Alarm -->
@@ -81,6 +82,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
  <phprelease>
   <filelist>
    <install name="lib/Horde/Alarm/Exception.php" as="Horde/Alarm/Exception.php" />
+   <install name="lib/Horde/Alarm/Null.php" as="Horde/Alarm/Null.php" />
    <install name="lib/Horde/Alarm/Object.php" as="Horde/Alarm/Object.php" />
    <install name="lib/Horde/Alarm/Sql.php" as="Horde/Alarm/Sql.php" />
    <install name="lib/Horde/Alarm.php" as="Horde/Alarm.php" />