Use injector to load IMP_Quota
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 14 Apr 2010 10:19:25 +0000 (04:19 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 14 Apr 2010 20:03:53 +0000 (14:03 -0600)
imp/lib/Application.php
imp/lib/IMP.php
imp/lib/Injector/Binder/Quota.php [new file with mode: 0644]
imp/lib/Quota.php

index 5d430c7..d36ba5b 100644 (file)
@@ -99,6 +99,7 @@ class IMP_Application extends Horde_Registry_Application
             'IMP_Folder' => new IMP_Injector_Binder_Folder(),
             'IMP_Identity' => new IMP_Injector_Binder_Identity(),
             'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(),
+            'IMP_Quota' => new IMP_Injector_Binder_Quota(),
             'IMP_Sentmail' => new IMP_Injector_Binder_Sentmail()
         );
 
index 34d4964..ce7a4e1 100644 (file)
@@ -601,9 +601,9 @@ class IMP
         }
 
         try {
-            $quotaDriver = IMP_Quota::singleton($_SESSION['imp']['imap']['quota']['driver'], isset($_SESSION['imp']['imap']['quota']['params']) ? $_SESSION['imp']['imap']['quota']['params'] : array());
+            $quotaDriver = $GLOBALS['injector']->getInstance('IMP_Quota');
             $quota = $quotaDriver->getQuota();
-        } catch (Horde_Exception $e) {
+        } catch (Exception $e) {
             Horde::logMessage($e, 'ERR');
             return false;
         }
diff --git a/imp/lib/Injector/Binder/Quota.php b/imp/lib/Injector/Binder/Quota.php
new file mode 100644 (file)
index 0000000..27a9140
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Binder for IMP_Quota::.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Injector_Binder_Quota implements Horde_Injector_Binder
+{
+    /**
+     */
+    public function create(Horde_Injector $injector)
+    {
+        return IMP_Quota::factory($_SESSION['imp']['imap']['quota']['driver'], isset($_SESSION['imp']['imap']['quota']['params']) ? $_SESSION['imp']['imap']['quota']['params'] : array());
+    }
+
+    /**
+     */
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
index f588a0b..9eaae8e 100644 (file)
 class IMP_Quota
 {
     /**
-     * Singleton instances.
-     *
-     * @var array
-     */
-    static protected $_instances = array();
-
-    /**
      * Hash containing connection parameters.
      *
      * @var array
@@ -28,34 +21,6 @@ class IMP_Quota
     protected $_params = array();
 
     /**
-     * Attempts to return a reference to a concrete IMP_Quota instance based on
-     * $driver.
-     *
-     * It will only create a new instance if no instance with the same
-     * parameters currently exists.
-     *
-     * This method must be invoked as: $var = IMP_Quota::singleton()
-     *
-     * @param string $driver  The type of concrete subclass to return.
-     * @param array $params   A hash containing any additional configuration
-     *                        or connection parameters a subclass might need.
-     *
-     * @return IMP_Quota  The concrete instance.
-     * @throws Horde_Exception
-     */
-    static public function singleton($driver, $params = array())
-    {
-        ksort($params);
-        $sig = hash('md5', serialize(array($driver, $params)));
-
-        if (!isset(self::$_instances[$sig])) {
-            self::$_instances[$sig] = self::factory($driver, $params);
-        }
-
-        return self::$_instances[$sig];
-    }
-
-    /**
      * Attempts to return a concrete instance based on $driver.
      *
      * @param string $driver  The type of concrete subclass to return.
@@ -63,7 +28,7 @@ class IMP_Quota
      *                        connection parameters a subclass might need.
      *
      * @return IMP_Quota  The concrete instance.
-     * @throws Horde_Exception
+     * @throws IMP_Exception
      */
     static public function factory($driver, $params = array())
     {
@@ -74,7 +39,7 @@ class IMP_Quota
             return new $class($params);
         }
 
-        throw new Horde_Exception('Could not create IMP_Quota instance: ' . $driver);
+        throw new IMP_Exception('Could not create ' . __CLASS__ .  ' instance: ' . $driver);
     }
 
     /**