From cbbf69b02148b50a053b3c5f336597cbafda9e7f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 7 Oct 2010 02:25:02 -0600 Subject: [PATCH] Convert all IMP binders to factories. --- imp/lib/Application.php | 26 ++++++------- imp/lib/Injector/Binder/Identity.php | 31 --------------- imp/lib/Injector/Binder/Smime.php | 31 --------------- imp/lib/Injector/{Binder => Factory}/AuthImap.php | 29 +++++++++----- imp/lib/Injector/Factory/Identity.php | 40 ++++++++++++++++++++ imp/lib/Injector/{Binder => Factory}/Imaptree.php | 46 +++++++++++++---------- imp/lib/Injector/{Binder => Factory}/Mail.php | 28 ++++++++++---- imp/lib/Injector/{Binder => Factory}/Pgp.php | 27 ++++++++----- imp/lib/Injector/{Binder => Factory}/Quota.php | 27 ++++++++----- imp/lib/Injector/{Binder => Factory}/Search.php | 45 +++++++++++----------- imp/lib/Injector/{Binder => Factory}/Sentmail.php | 27 ++++++++----- imp/lib/Injector/Factory/Smime.php | 40 ++++++++++++++++++++ 12 files changed, 234 insertions(+), 163 deletions(-) delete mode 100644 imp/lib/Injector/Binder/Identity.php delete mode 100644 imp/lib/Injector/Binder/Smime.php rename imp/lib/Injector/{Binder => Factory}/AuthImap.php (64%) create mode 100644 imp/lib/Injector/Factory/Identity.php rename imp/lib/Injector/{Binder => Factory}/Imaptree.php (65%) rename imp/lib/Injector/{Binder => Factory}/Mail.php (77%) rename imp/lib/Injector/{Binder => Factory}/Pgp.php (64%) rename imp/lib/Injector/{Binder => Factory}/Quota.php (76%) rename imp/lib/Injector/{Binder => Factory}/Search.php (63%) rename imp/lib/Injector/{Binder => Factory}/Sentmail.php (63%) create mode 100644 imp/lib/Injector/Factory/Smime.php diff --git a/imp/lib/Application.php b/imp/lib/Application.php index c1ce8f4a6..b1e8f9c5b 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -88,21 +88,21 @@ class IMP_Application extends Horde_Registry_Application */ protected function _init() { - /* Add IMP-specific binders. */ - $binders = array( - 'IMP_AuthImap' => new IMP_Injector_Binder_AuthImap(), - 'IMP_Crypt_Pgp' => new IMP_Injector_Binder_Pgp(), - 'IMP_Crypt_Smime' => new IMP_Injector_Binder_Smime(), - 'IMP_Identity' => new IMP_Injector_Binder_Identity(), - 'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(), - 'IMP_Mail' => new IMP_Injector_Binder_Mail(), - 'IMP_Quota' => new IMP_Injector_Binder_Quota(), - 'IMP_Search' => new IMP_Injector_Binder_Search(), - 'IMP_Sentmail' => new IMP_Injector_Binder_Sentmail() + /* Add IMP-specific factories. */ + $factories = array( + 'IMP_AuthImap' => 'IMP_Injector_Factory_AuthImap', + 'IMP_Crypt_Pgp' => 'IMP_Injector_Factory_Pgp', + 'IMP_Crypt_Smime' => 'IMP_Injector_Factory_Smime', + 'IMP_Identity' => 'IMP_Injector_Factory_Identity', + 'IMP_Imap_Tree' => 'IMP_Injector_Factory_Imaptree', + 'IMP_Mail' => 'IMP_Injector_Factory_Mail', + 'IMP_Quota' => 'IMP_Injector_Factory_Quota', + 'IMP_Search' => 'IMP_Injector_Factory_Search', + 'IMP_Sentmail' => 'IMP_Injector_Factory_Sentmail' ); - foreach ($binders as $key => $val) { - $GLOBALS['injector']->addBinder($key, $val); + foreach ($factories as $key => $val) { + $GLOBALS['injector']->bindFactory($key, $val, 'create'); } // Set default message character set. diff --git a/imp/lib/Injector/Binder/Identity.php b/imp/lib/Injector/Binder/Identity.php deleted file mode 100644 index 1c0b91b97..000000000 --- a/imp/lib/Injector/Binder/Identity.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Identity implements Horde_Injector_Binder -{ - /** - */ - public function create(Horde_Injector $injector) - { - return $injector->getInstance('Horde_Prefs_Identity')->getIdentity(null, 'imp'); - } - - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - -} diff --git a/imp/lib/Injector/Binder/Smime.php b/imp/lib/Injector/Binder/Smime.php deleted file mode 100644 index 5769ef59b..000000000 --- a/imp/lib/Injector/Binder/Smime.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Smime implements Horde_Injector_Binder -{ - /** - */ - public function create(Horde_Injector $injector) - { - return $injector->getInstance('Horde_Core_Factory_Crypt')->create('IMP_Crypt_Smime'); - } - - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - -} diff --git a/imp/lib/Injector/Binder/AuthImap.php b/imp/lib/Injector/Factory/AuthImap.php similarity index 64% rename from imp/lib/Injector/Binder/AuthImap.php rename to imp/lib/Injector/Factory/AuthImap.php index de61c91d7..059e94d30 100644 --- a/imp/lib/Injector/Binder/AuthImap.php +++ b/imp/lib/Injector/Factory/AuthImap.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based Horde_Auth_Imap:: factory. * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,18 +22,22 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_AuthImap implements Horde_Injector_Binder +class IMP_Injector_Factory_AuthImap { /** + * Return the Horde_Auth_Imap:: instance that uses IMP configuration. + * + * @return Horde_Auth_Imap The singleton instance. * @throws IMP_Exception */ public function create(Horde_Injector $injector) { $params = $GLOBALS['registry']->callByPackage('imp', 'server'); if (is_null($params)) { - throw new IMP_Exception('No mail parameters found.'); + throw new IMP_Exception('No server parameters found.'); } $params = array_merge( @@ -41,11 +57,4 @@ class IMP_Injector_Binder_AuthImap implements Horde_Injector_Binder return Horde_Auth::factory('imap', $params); } - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - } diff --git a/imp/lib/Injector/Factory/Identity.php b/imp/lib/Injector/Factory/Identity.php new file mode 100644 index 000000000..21132d52d --- /dev/null +++ b/imp/lib/Injector/Factory/Identity.php @@ -0,0 +1,40 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for IMP's identity object. + * + * 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 + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ +class IMP_Injector_Factory_Identity +{ + /** + * Return the IMP identity instance. + * + * @return IMP_Prefs_Identity The singleton instance. + */ + public function create(Horde_Injector $injector) + { + return $injector->getInstance('Horde_Prefs_Identity')->getIdentity(null, 'imp'); + } + +} diff --git a/imp/lib/Injector/Binder/Imaptree.php b/imp/lib/Injector/Factory/Imaptree.php similarity index 65% rename from imp/lib/Injector/Binder/Imaptree.php rename to imp/lib/Injector/Factory/Imaptree.php index 7ee2bf96f..7a8535e38 100644 --- a/imp/lib/Injector/Binder/Imaptree.php +++ b/imp/lib/Injector/Factory/Imaptree.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for the IMP_Imap_Tree object. * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,27 +22,22 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder +class IMP_Injector_Factory_Imaptree { /** - * Injector. + * Return the IMP_Imap_Tree object. * - * @var Horde_Injector - */ - private $_injector; - - /** - * If an IMP_Imap_Tree object is currently stored in the cache, re-create - * that object. Else, create a new instance. + * @return IMP_Imap_Tree The singleton instance. */ public function create(Horde_Injector $injector) { - $this->_injector = $injector; - $instance = null; + /* If an IMP_Imap_Tree object is currently stored in the cache, + * re-create that object. Else, create a new instance. */ if (empty($_SESSION['imp']['cache']['tree'])) { $_SESSION['imp']['cache']['tree'] = strval(new Horde_Support_Randomid()); } else { @@ -52,28 +59,27 @@ class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder $instance = new IMP_Imap_Tree(); } - register_shutdown_function(array($this, 'shutdown'), $instance); + register_shutdown_function(array($this, 'shutdown'), $instance, $injector); return $instance; } /** * Store serialized version of object in the current session. + * + * @param IMP_Imap_Tree $instance Tree object. + * @param Horde_Injector $injector Injector object. */ - public function shutdown($instance) + public function shutdown($instance, $injector) { /* Only need to store the object if the tree has changed. */ if ($instance->changed) { - $cache = $this->_injector->getInstance('Horde_Cache'); + $cache = $injector->getInstance('Horde_Cache'); if ($cache instanceof Horde_Cache_Null) { - $cache = $this->_injector->getInstance('Horde_Cache_Session'); + $cache = $injector->getInstance('Horde_Cache_Session'); } $cache->set($_SESSION['imp']['cache']['tree'], serialize($instance), 86400); } } - public function equals(Horde_Injector_Binder $binder) - { - return false; - } } diff --git a/imp/lib/Injector/Binder/Mail.php b/imp/lib/Injector/Factory/Mail.php similarity index 77% rename from imp/lib/Injector/Binder/Mail.php rename to imp/lib/Injector/Factory/Mail.php index b8d104b26..ad8ff2cf2 100644 --- a/imp/lib/Injector/Binder/Mail.php +++ b/imp/lib/Injector/Factory/Mail.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for IMP's configuration of Horde_Mail:: * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,11 +22,16 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_Mail implements Horde_Injector_Binder +class IMP_Injector_Factory_Mail { /** + * Return the Horde_Mail instance. + * + * @return Horde_Mail The singleton instance. + * @throws Horde_Exception */ public function create(Horde_Injector $injector) { @@ -46,13 +63,8 @@ class IMP_Injector_Binder_Mail implements Horde_Injector_Binder if (class_exists($class)) { return new $class($params); } + throw new Horde_Exception('Unable to find class for transport ' . $transport); } - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } } diff --git a/imp/lib/Injector/Binder/Pgp.php b/imp/lib/Injector/Factory/Pgp.php similarity index 64% rename from imp/lib/Injector/Binder/Pgp.php rename to imp/lib/Injector/Factory/Pgp.php index 1d7e222d9..6a5f41c3d 100644 --- a/imp/lib/Injector/Binder/Pgp.php +++ b/imp/lib/Injector/Factory/Pgp.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for the IMP_Crypt_Pgp object. * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,11 +22,15 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_Pgp implements Horde_Injector_Binder +class IMP_Injector_Factory_Pgp { /** + * Return the IMP_Crypt_Pgp instance. + * + * @return IMP_Crypt_Pgp The singleton instance. */ public function create(Horde_Injector $injector) { @@ -32,11 +48,4 @@ class IMP_Injector_Binder_Pgp implements Horde_Injector_Binder return $injector->getInstance('Horde_Core_Factory_Crypt')->create('IMP_Crypt_Pgp', $params); } - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - } diff --git a/imp/lib/Injector/Binder/Quota.php b/imp/lib/Injector/Factory/Quota.php similarity index 76% rename from imp/lib/Injector/Binder/Quota.php rename to imp/lib/Injector/Factory/Quota.php index d7c320975..3128fe1ad 100644 --- a/imp/lib/Injector/Binder/Quota.php +++ b/imp/lib/Injector/Factory/Quota.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for the IMP_Quota object. * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,11 +22,15 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_Quota implements Horde_Injector_Binder +class IMP_Injector_Factory_Quota { /** + * Return the IMP_Quota instance. + * + * @return IMP_Quota The singleton instance. */ public function create(Horde_Injector $injector) { @@ -50,11 +66,4 @@ class IMP_Injector_Binder_Quota implements Horde_Injector_Binder return IMP_Quota::factory($driver, $params); } - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - } diff --git a/imp/lib/Injector/Binder/Search.php b/imp/lib/Injector/Factory/Search.php similarity index 63% rename from imp/lib/Injector/Binder/Search.php rename to imp/lib/Injector/Factory/Search.php index 2172ad072..7240948d7 100644 --- a/imp/lib/Injector/Binder/Search.php +++ b/imp/lib/Injector/Factory/Search.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for the IMP_Search object. * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,27 +22,18 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_Search implements Horde_Injector_Binder +class IMP_Injector_Factory_Search { /** - * Injector. - * - * @var Horde_Injector - */ - private $_injector; - - /** - * If an IMP_Search object is currently stored in the session, re-create - * that object. Else, create a new instance. + * Return the IMP_Search instance. * - * @param Horde_Injecton $injector Parent injector. + * @return IMP_Search The singleton instance. */ public function create(Horde_Injector $injector) { - $this->_injector = $injector; - $instance = null; if (!empty($_SESSION['imp']['search'])) { @@ -45,15 +48,18 @@ class IMP_Injector_Binder_Search implements Horde_Injector_Binder $instance = new IMP_Search(); } - register_shutdown_function(array($this, 'shutdown'), $instance); + register_shutdown_function(array($this, 'shutdown'), $instance, $injector); return $instance; } /** * Store serialized version of object in the current session. + * + * @param IMP_Search $instance Tree object. + * @param Horde_Injector $injector Injector object. */ - public function shutdown($instance) + public function shutdown($instance, $injector) { /* Only need to store the object if the object has changed. */ if ($instance->changed) { @@ -61,11 +67,4 @@ class IMP_Injector_Binder_Search implements Horde_Injector_Binder } } - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - } diff --git a/imp/lib/Injector/Binder/Sentmail.php b/imp/lib/Injector/Factory/Sentmail.php similarity index 63% rename from imp/lib/Injector/Binder/Sentmail.php rename to imp/lib/Injector/Factory/Sentmail.php index aab68425e..a31505822 100644 --- a/imp/lib/Injector/Binder/Sentmail.php +++ b/imp/lib/Injector/Factory/Sentmail.php @@ -1,6 +1,18 @@ + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for the IMP_Sentmail object. * * Copyright 2010 The Horde Project (http://www.horde.org/) * @@ -10,11 +22,15 @@ * @author Michael Slusarz * @category Horde * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP * @package IMP */ -class IMP_Injector_Binder_Sentmail implements Horde_Injector_Binder +class IMP_Injector_Factory_Sentmail { /** + * Return the IMP_Sentmail instance. + * + * @return IMP_Sentmail The singleton instance. */ public function create(Horde_Injector $injector) { @@ -32,11 +48,4 @@ class IMP_Injector_Binder_Sentmail implements Horde_Injector_Binder return IMP_Sentmail::factory($driver, $params); } - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - } diff --git a/imp/lib/Injector/Factory/Smime.php b/imp/lib/Injector/Factory/Smime.php new file mode 100644 index 000000000..bb49da5c0 --- /dev/null +++ b/imp/lib/Injector/Factory/Smime.php @@ -0,0 +1,40 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ + +/** + * A Horde_Injector based factory for the IMP_Crypt_Smime object. + * + * 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 + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + * @package IMP + */ +class IMP_Injector_Factory_Smime +{ + /** + * Return the IMP_Crypt_Smime instance. + * + * @return IMP_Crypt_Smime The singleton instance. + */ + public function create(Horde_Injector $injector) + { + return $injector->getInstance('Horde_Core_Factory_Crypt')->create('IMP_Crypt_Smime'); + } + +} -- 2.11.0