Continue the saga of moving binders to factories... Horde_Alarm this time.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 3 Oct 2010 02:25:54 +0000 (22:25 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 3 Oct 2010 02:26:28 +0000 (22:26 -0400)
framework/Core/lib/Horde/Core/Factory/Alarm.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml

diff --git a/framework/Core/lib/Horde/Core/Factory/Alarm.php b/framework/Core/lib/Horde/Core/Factory/Alarm.php
new file mode 100644 (file)
index 0000000..2b448cd
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/**
+ * A Horde_Injector:: based Horde_Alarm:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Core
+ * @author   Michael J. Rubinsky <mrubinsk@horde.org>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Core
+ */
+
+/**
+ * A Horde_Injector:: based Horde_Core_Ajax_Application:: factory.
+ *
+ * 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.
+ *
+ * @category Horde
+ * @package  Core
+ * @author   Michael J. Rubinsky <mrubinsk@horde.org>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Core
+ */
+class Horde_Core_Factory_Alarm
+{
+    /**
+     * Return a Horde_Alarm instance
+     * 
+     */
+    public function create(Horde_Injector $injector)
+    {
+        $driver = empty($GLOBALS['conf']['alarms']['driver'])
+            ? 'Null'
+            : $GLOBALS['conf']['alarms']['driver'];
+
+        $params = Horde::getDriverConfig('alarms', $driver);
+
+        if (strcasecmp($driver, 'Sql') === 0) {
+            $params['db'] = $injector->getInstance('Horde_Db')->getDb('horde', 'alarm');
+            $config = $injector->getInstance('Horde_Db')->getConfig('alarm');
+            $params['charset'] = $config['charset'];
+        }
+
+        $params['logger'] = $injector->getInstance('Horde_Log_Logger');
+
+        $class = 'Horde_Alarm_' . $driver;
+        $alarm = new $class($params);
+        $alarm->initialize();
+        $alarm->gc();
+
+        /* Add those handlers that need configuration and can't be auto-loaded
+         * through Horde_Alarms::handlers(). */
+        /*
+        $handler_params = array(
+            'notification' => $injector->getInstance('Horde_Notification')
+        );
+        $alarm->addHandler('notify', new Horde_Alarm_Handler_Notification($handler_params)
+        );
+
+        $handler_params = array(
+            'js_notify' => array('Horde', 'addInlineScript'),
+            'icon' => (string)Horde_Themes::img('alerts/alarm.png')
+        );
+        $alarm->addHandler('desktop', new Horde_Alarm_Handler_Desktop($handler_params));
+        */
+
+        $handler_params = array(
+            'identity' => $injector->getInstance('Horde_Prefs_Identity'),
+            'mail' => $injector->getInstance('Horde_Mail'),
+            'charset' => $GLOBALS['registry']->getCharset()
+        );
+        $alarm->addHandler('mail', new Horde_Alarm_Handler_Mail($handler_params));
+
+        return $alarm;
+    }
+
+}
index 6712ba4..c6514ef 100644 (file)
@@ -264,7 +264,6 @@ class Horde_Registry
 
         /* Define binders. */
         $binders = array(
-            'Horde_Alarm' => 'Horde_Core_Binder_Alarm',
             'Horde_Auth_Factory' => 'Horde_Core_Binder_AuthFactory',
             // 'Horde_Browser' - initialized below
             'Horde_Core_Auth_Signup' => 'Horde_Core_Binder_AuthSignup',
@@ -303,6 +302,10 @@ class Horde_Registry
 
         /* Define factories. */
         $factories = array(
+            'Horde_Alarm' => array(
+                'Horde_Core_Factory_Alarm',
+                'create'
+            ),
             'Horde_Cache' => array(
                 'Horde_Core_Factory_Cache',
                 'create',
index 7876d35..a173483 100644 (file)
@@ -110,7 +110,6 @@ Application Framework.</description>
        </dir> <!-- /lib/Horde/Core/Autoloader/Callback -->
       </dir> <!-- /lib/Horde/Core/Autoloader -->
       <dir name="Binder">
-       <file name="Alarm.php" role="php" />
        <file name="Auth.php" role="php" />
        <file name="AuthFactory.php" role="php" />
        <file name="AuthSignup.php" role="php" />
@@ -153,6 +152,7 @@ Application Framework.</description>
       </dir> <!-- /lib/Horde/Core/Controller -->
       <dir name="Factory">
        <file name="Ajax.php" role="php" />
+       <file name="Alarm.php" role="php" />
        <file name="Auth.php" role="php" />
        <file name="Cache.php" role="php" />
        <file name="Crypt.php" role="php" />
@@ -431,7 +431,6 @@ Application Framework.</description>
    <install as="Horde/Core/Auth/Signup/SqlObject.php" name="lib/Horde/Core/Auth/Signup/SqlObject.php" />
    <install as="Horde/Core/Autoloader/Callback/Mime.php" name="lib/Horde/Core/Autoloader/Callback/Mime.php" />
    <install as="Horde/Core/Autoloader/Callback/Nls.php" name="lib/Horde/Core/Autoloader/Callback/Nls.php" />
-   <install as="Horde/Core/Binder/Alarm.php" name="lib/Horde/Core/Binder/Alarm.php" />
    <install as="Horde/Core/Binder/Auth.php" name="lib/Horde/Core/Binder/Auth.php" />
    <install as="Horde/Core/Binder/AuthFactory.php" name="lib/Horde/Core/Binder/AuthFactory.php" />
    <install as="Horde/Core/Binder/AuthSignup.php" name="lib/Horde/Core/Binder/AuthSignup.php" />
@@ -470,6 +469,7 @@ Application Framework.</description>
    <install as="Horde/Core/Controller/RequestMapper.php" name="lib/Horde/Core/Controller/RequestMapper.php" />
    <install as="Horde/Core/Controller/SettingsFinder.php" name="lib/Horde/Core/Controller/SettingsFinder.php" />
    <install as="Horde/Core/Factory/Ajax.php" name="lib/Horde/Core/Factory/Ajax.php" />
+   <install as="Horde/Core/Factory/Alarm.php" name="lib/Horde/Core/Factory/Alarm.php" />
    <install as="Horde/Core/Factory/Auth.php" name="lib/Horde/Core/Factory/Auth.php" />
    <install as="Horde/Core/Factory/Cache.php" name="lib/Horde/Core/Factory/Cache.php" />
    <install as="Horde/Core/Factory/Crypt.php" name="lib/Horde/Core/Factory/Crypt.php" />