New singelton style.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 13 Feb 2009 07:54:11 +0000 (00:54 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 14 Feb 2009 20:31:20 +0000 (13:31 -0700)
imp/lib/IMAP/ACL.php
imp/lib/Mailbox.php
imp/lib/Quota.php

index 31bba9d..13f7d55 100644 (file)
 class IMP_IMAP_ACL
 {
     /**
+     * Singleton instance.
+     *
+     * @var IMP_IMAP_ACL
+     */
+    static protected $_instance = null;
+
+    /**
      * Hash containing the list of possible rights and a human readable
      * description of each.
      *
@@ -32,26 +39,21 @@ class IMP_IMAP_ACL
      * Attempts to return a reference to a concrete object instance.
      * It will only create a new instance if no instance currently exists.
      *
-     * This method must be invoked as:
-     *   $var = &IMP_IMAP_ACL::singleton()
-     *
      * @return IMP_IMAP_ACL  The created concrete instance.
      */
-    static public function &singleton($driver, $params = array())
+    static public function singleton()
     {
-        static $instance;
-
-        if (!isset($instance)) {
-            $instances = new IMP_IMAP_ACL();
+        if (!self::$_instance) {
+            self::$_instance = new IMP_IMAP_ACL();
         }
 
-        return $instances[$signature];
+        return self::$_instance;
     }
 
     /**
      * Constructor.
      */
-    function __construct()
+    protected function __construct()
     {
         if ($_SESSION['imp']['protocol'] != 'imap') {
             throw new Exception(_("ACL requires an IMAP server."));
index 8479a65..998ab27 100644 (file)
@@ -15,6 +15,7 @@ class IMP_Mailbox
 {
     /**
      * Singleton instances
+     *
      * @var array
      */
     protected static $_instances = array();
index aeeddc8..7539ec2 100644 (file)
 class IMP_Quota
 {
     /**
+     * Singleton instances.
+     *
+     * @var array
+     */
+    static protected $_instances = array();
+
+    /**
      * Hash containing connection parameters.
      *
      * @var array
@@ -35,16 +42,16 @@ class IMP_Quota
      *
      * @return mixed  The created concrete instance, or false on error.
      */
-    static public function &singleton($driver, $params = array())
+    static public function singleton($driver, $params = array())
     {
-        static $instances = array();
+        ksort($params);
+        $signature = md5(serialize(array($driver, $params)));
 
-        $signature = serialize(array($driver, $params));
-        if (!isset($instances[$signature])) {
-            $instances[$signature] = IMP_Quota::factory($driver, $params);
+        if (!isset(self::$_instances[$signature])) {
+            self::$_instances[$signature] = IMP_Quota::factory($driver, $params);
         }
 
-        return $instances[$signature];
+        return self::$_instances[$signature];
     }
 
     /**