From 30fbebf8e0d9bea972c2de3f4067e15b74f3c54a Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 13 Feb 2009 00:54:11 -0700 Subject: [PATCH] New singelton style. --- imp/lib/IMAP/ACL.php | 22 ++++++++++++---------- imp/lib/Mailbox.php | 1 + imp/lib/Quota.php | 19 +++++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/imp/lib/IMAP/ACL.php b/imp/lib/IMAP/ACL.php index 31bba9db2..13f7d55c6 100644 --- a/imp/lib/IMAP/ACL.php +++ b/imp/lib/IMAP/ACL.php @@ -13,6 +13,13 @@ 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.")); diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index 8479a65af..998ab276c 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -15,6 +15,7 @@ class IMP_Mailbox { /** * Singleton instances + * * @var array */ protected static $_instances = array(); diff --git a/imp/lib/Quota.php b/imp/lib/Quota.php index aeeddc8d2..7539ec2b8 100644 --- a/imp/lib/Quota.php +++ b/imp/lib/Quota.php @@ -14,6 +14,13 @@ 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]; } /** -- 2.11.0