From: Michael M Slusarz Date: Thu, 7 Oct 2010 08:25:02 +0000 (-0600) Subject: Convert all IMP binders to factories. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=cbbf69b02148b50a053b3c5f336597cbafda9e7f;p=horde.git Convert all IMP binders to factories. --- 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/AuthImap.php b/imp/lib/Injector/Binder/AuthImap.php deleted file mode 100644 index de61c91d7..000000000 --- a/imp/lib/Injector/Binder/AuthImap.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_AuthImap implements Horde_Injector_Binder -{ - /** - * @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.'); - } - - $params = array_merge( - $params, - $_SESSION['imp']['imap']['admin']['params'], - array( - 'default_user' => $GLOBALS['registry']->getAuth(), - 'logger' => $injector->getInstance('Horde_Log_Logger') - ) - ); - - if (isset($params['admin_password'])) { - $secret = $injector->getInstance('Horde_Secret'); - $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']); - } - - return Horde_Auth::factory('imap', $params); - } - - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - -} 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/Imaptree.php b/imp/lib/Injector/Binder/Imaptree.php deleted file mode 100644 index 7ee2bf96f..000000000 --- a/imp/lib/Injector/Binder/Imaptree.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder -{ - /** - * Injector. - * - * @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. - */ - public function create(Horde_Injector $injector) - { - $this->_injector = $injector; - - $instance = null; - - if (empty($_SESSION['imp']['cache']['tree'])) { - $_SESSION['imp']['cache']['tree'] = strval(new Horde_Support_Randomid()); - } else { - /* Since IMAP tree generation is so expensive/time-consuming, - * fallback to storing in the session even if no permanent cache - * backend is setup. */ - $cache = $injector->getInstance('Horde_Cache'); - if ($cache instanceof Horde_Cache_Null) { - $cache = $injector->getInstance('Horde_Cache_Session'); - } - try { - $instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400)); - } catch (Exception $e) { - Horde::logMessage('Could not unserialize stored IMP_Imap_Tree object.', 'DEBUG'); - } - } - - if (!($instance instanceof IMP_Imap_Tree)) { - $instance = new IMP_Imap_Tree(); - } - - register_shutdown_function(array($this, 'shutdown'), $instance); - - return $instance; - } - - /** - * Store serialized version of object in the current session. - */ - public function shutdown($instance) - { - /* Only need to store the object if the tree has changed. */ - if ($instance->changed) { - $cache = $this->_injector->getInstance('Horde_Cache'); - if ($cache instanceof Horde_Cache_Null) { - $cache = $this->_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/Binder/Mail.php deleted file mode 100644 index b8d104b26..000000000 --- a/imp/lib/Injector/Binder/Mail.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Mail implements Horde_Injector_Binder -{ - /** - */ - public function create(Horde_Injector $injector) - { - /* We don't actually want to alter the contents of the $conf['mailer'] - * array, so we make a copy of the current settings. We will apply our - * modifications (if any) to the copy, instead. */ - $params = $GLOBALS['conf']['mailer']['params']; - - /* Force the SMTP host and port value to the current SMTP server if - * one has been selected for this connection. */ - if (!empty($_SESSION['imp']['smtp'])) { - $params = array_merge($params, $_SESSION['imp']['smtp']); - } - - /* If SMTP authentication has been requested, use either the username - * and password provided in the configuration or populate the username - * and password fields based on the current values for the user. Note - * that we assume that the username and password values from the - * current IMAP / POP3 connection are valid for SMTP authentication as - * well. */ - if (!empty($params['auth']) && empty($params['username'])) { - $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); - $params['username'] = $imap_ob->getParam('username'); - $params['password'] = $imap_ob->getParam('password'); - } - - $transport = $GLOBALS['conf']['mailer']['type']; - $class = 'Horde_Mail_Transport_' . ucfirst($transport); - 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/Binder/Pgp.php deleted file mode 100644 index 1d7e222d9..000000000 --- a/imp/lib/Injector/Binder/Pgp.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Pgp implements Horde_Injector_Binder -{ - /** - */ - public function create(Horde_Injector $injector) - { - $params = array( - 'program' => $GLOBALS['conf']['gnupg']['path'] - ); - - if (isset($GLOBALS['conf']['http']['proxy']['proxy_host'])) { - $params['proxy_host'] = $GLOBALS['conf']['http']['proxy']['proxy_host']; - if (isset($GLOBALS['conf']['http']['proxy']['proxy_port'])) { - $params['proxy_port'] = $GLOBALS['conf']['http']['proxy']['proxy_port']; - } - } - - 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/Binder/Quota.php deleted file mode 100644 index d7c320975..000000000 --- a/imp/lib/Injector/Binder/Quota.php +++ /dev/null @@ -1,60 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Quota implements Horde_Injector_Binder -{ - /** - */ - public function create(Horde_Injector $injector) - { - $driver = $_SESSION['imp']['imap']['quota']['driver']; - $params = isset($_SESSION['imp']['imap']['quota']['params']) - ? $_SESSION['imp']['imap']['quota']['params'] - : array(); - - /* If 'password' exists in params, it has been encrypted in the - * session so we need to decrypt. */ - if (isset($params['password'])) { - $secret = $injector->getInstance('Horde_Secret'); - $params['password'] = $secret->read($secret->getKey('imp'), $params['password']); - } - - switch (Horde_String::lower($driver)) { - case 'imap': - $params['imap_ob'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); - $params['mbox'] = $injector->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) - ? 'INBOX' - : IMP::$mailbox; - break; - - case 'maildir': - $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username'); - break; - - case 'sql': - $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params); - break; - } - - 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/Binder/Search.php deleted file mode 100644 index 2172ad072..000000000 --- a/imp/lib/Injector/Binder/Search.php +++ /dev/null @@ -1,71 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Search implements Horde_Injector_Binder -{ - /** - * 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. - * - * @param Horde_Injecton $injector Parent injector. - */ - public function create(Horde_Injector $injector) - { - $this->_injector = $injector; - - $instance = null; - - if (!empty($_SESSION['imp']['search'])) { - try { - $instance = @unserialize($_SESSION['imp']['search']); - } catch (Exception $e) { - Horde::logMessage('Could not unserialize stored IMP_Search object.', 'DEBUG'); - } - } - - if (is_null($instance)) { - $instance = new IMP_Search(); - } - - register_shutdown_function(array($this, 'shutdown'), $instance); - - return $instance; - } - - /** - * Store serialized version of object in the current session. - */ - public function shutdown($instance) - { - /* Only need to store the object if the object has changed. */ - if ($instance->changed) { - $_SESSION['imp']['search'] = serialize($instance); - } - } - - /** - */ - public function equals(Horde_Injector_Binder $binder) - { - return false; - } - -} diff --git a/imp/lib/Injector/Binder/Sentmail.php b/imp/lib/Injector/Binder/Sentmail.php deleted file mode 100644 index aab68425e..000000000 --- a/imp/lib/Injector/Binder/Sentmail.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ -class IMP_Injector_Binder_Sentmail implements Horde_Injector_Binder -{ - /** - */ - public function create(Horde_Injector $injector) - { - $driver = empty($GLOBALS['conf']['sentmail']['driver']) - ? 'Null' - : $GLOBALS['conf']['sentmail']['driver']; - $params = Horde::getDriverConfig('sentmail', $driver); - - if (strcasecmp($driver, 'Sql') === 0) { - $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', 'sentmail'); - } elseif (strcasecmp($driver, 'None') === 0) { - $driver = 'Null'; - } - - return IMP_Sentmail::factory($driver, $params); - } - - /** - */ - 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/Factory/AuthImap.php b/imp/lib/Injector/Factory/AuthImap.php new file mode 100644 index 000000000..059e94d30 --- /dev/null +++ b/imp/lib/Injector/Factory/AuthImap.php @@ -0,0 +1,60 @@ + + * @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/) + * + * 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_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 server parameters found.'); + } + + $params = array_merge( + $params, + $_SESSION['imp']['imap']['admin']['params'], + array( + 'default_user' => $GLOBALS['registry']->getAuth(), + 'logger' => $injector->getInstance('Horde_Log_Logger') + ) + ); + + if (isset($params['admin_password'])) { + $secret = $injector->getInstance('Horde_Secret'); + $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']); + } + + return Horde_Auth::factory('imap', $params); + } + +} 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/Factory/Imaptree.php b/imp/lib/Injector/Factory/Imaptree.php new file mode 100644 index 000000000..7a8535e38 --- /dev/null +++ b/imp/lib/Injector/Factory/Imaptree.php @@ -0,0 +1,85 @@ + + * @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/) + * + * 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_Imaptree +{ + /** + * Return the IMP_Imap_Tree object. + * + * @return IMP_Imap_Tree The singleton instance. + */ + public function create(Horde_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 { + /* Since IMAP tree generation is so expensive/time-consuming, + * fallback to storing in the session even if no permanent cache + * backend is setup. */ + $cache = $injector->getInstance('Horde_Cache'); + if ($cache instanceof Horde_Cache_Null) { + $cache = $injector->getInstance('Horde_Cache_Session'); + } + try { + $instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400)); + } catch (Exception $e) { + Horde::logMessage('Could not unserialize stored IMP_Imap_Tree object.', 'DEBUG'); + } + } + + if (!($instance instanceof IMP_Imap_Tree)) { + $instance = new IMP_Imap_Tree(); + } + + 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, $injector) + { + /* Only need to store the object if the tree has changed. */ + if ($instance->changed) { + $cache = $injector->getInstance('Horde_Cache'); + if ($cache instanceof Horde_Cache_Null) { + $cache = $injector->getInstance('Horde_Cache_Session'); + } + $cache->set($_SESSION['imp']['cache']['tree'], serialize($instance), 86400); + } + } + +} diff --git a/imp/lib/Injector/Factory/Mail.php b/imp/lib/Injector/Factory/Mail.php new file mode 100644 index 000000000..ad8ff2cf2 --- /dev/null +++ b/imp/lib/Injector/Factory/Mail.php @@ -0,0 +1,70 @@ + + * @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/) + * + * 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_Mail +{ + /** + * Return the Horde_Mail instance. + * + * @return Horde_Mail The singleton instance. + * @throws Horde_Exception + */ + public function create(Horde_Injector $injector) + { + /* We don't actually want to alter the contents of the $conf['mailer'] + * array, so we make a copy of the current settings. We will apply our + * modifications (if any) to the copy, instead. */ + $params = $GLOBALS['conf']['mailer']['params']; + + /* Force the SMTP host and port value to the current SMTP server if + * one has been selected for this connection. */ + if (!empty($_SESSION['imp']['smtp'])) { + $params = array_merge($params, $_SESSION['imp']['smtp']); + } + + /* If SMTP authentication has been requested, use either the username + * and password provided in the configuration or populate the username + * and password fields based on the current values for the user. Note + * that we assume that the username and password values from the + * current IMAP / POP3 connection are valid for SMTP authentication as + * well. */ + if (!empty($params['auth']) && empty($params['username'])) { + $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $params['username'] = $imap_ob->getParam('username'); + $params['password'] = $imap_ob->getParam('password'); + } + + $transport = $GLOBALS['conf']['mailer']['type']; + $class = 'Horde_Mail_Transport_' . ucfirst($transport); + if (class_exists($class)) { + return new $class($params); + } + + throw new Horde_Exception('Unable to find class for transport ' . $transport); + } + +} diff --git a/imp/lib/Injector/Factory/Pgp.php b/imp/lib/Injector/Factory/Pgp.php new file mode 100644 index 000000000..6a5f41c3d --- /dev/null +++ b/imp/lib/Injector/Factory/Pgp.php @@ -0,0 +1,51 @@ + + * @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/) + * + * 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_Pgp +{ + /** + * Return the IMP_Crypt_Pgp instance. + * + * @return IMP_Crypt_Pgp The singleton instance. + */ + public function create(Horde_Injector $injector) + { + $params = array( + 'program' => $GLOBALS['conf']['gnupg']['path'] + ); + + if (isset($GLOBALS['conf']['http']['proxy']['proxy_host'])) { + $params['proxy_host'] = $GLOBALS['conf']['http']['proxy']['proxy_host']; + if (isset($GLOBALS['conf']['http']['proxy']['proxy_port'])) { + $params['proxy_port'] = $GLOBALS['conf']['http']['proxy']['proxy_port']; + } + } + + return $injector->getInstance('Horde_Core_Factory_Crypt')->create('IMP_Crypt_Pgp', $params); + } + +} diff --git a/imp/lib/Injector/Factory/Quota.php b/imp/lib/Injector/Factory/Quota.php new file mode 100644 index 000000000..3128fe1ad --- /dev/null +++ b/imp/lib/Injector/Factory/Quota.php @@ -0,0 +1,69 @@ + + * @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/) + * + * 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_Quota +{ + /** + * Return the IMP_Quota instance. + * + * @return IMP_Quota The singleton instance. + */ + public function create(Horde_Injector $injector) + { + $driver = $_SESSION['imp']['imap']['quota']['driver']; + $params = isset($_SESSION['imp']['imap']['quota']['params']) + ? $_SESSION['imp']['imap']['quota']['params'] + : array(); + + /* If 'password' exists in params, it has been encrypted in the + * session so we need to decrypt. */ + if (isset($params['password'])) { + $secret = $injector->getInstance('Horde_Secret'); + $params['password'] = $secret->read($secret->getKey('imp'), $params['password']); + } + + switch (Horde_String::lower($driver)) { + case 'imap': + $params['imap_ob'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + $params['mbox'] = $injector->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) + ? 'INBOX' + : IMP::$mailbox; + break; + + case 'maildir': + $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username'); + break; + + case 'sql': + $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params); + break; + } + + return IMP_Quota::factory($driver, $params); + } + +} diff --git a/imp/lib/Injector/Factory/Search.php b/imp/lib/Injector/Factory/Search.php new file mode 100644 index 000000000..7240948d7 --- /dev/null +++ b/imp/lib/Injector/Factory/Search.php @@ -0,0 +1,70 @@ + + * @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/) + * + * 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_Search +{ + /** + * Return the IMP_Search instance. + * + * @return IMP_Search The singleton instance. + */ + public function create(Horde_Injector $injector) + { + $instance = null; + + if (!empty($_SESSION['imp']['search'])) { + try { + $instance = @unserialize($_SESSION['imp']['search']); + } catch (Exception $e) { + Horde::logMessage('Could not unserialize stored IMP_Search object.', 'DEBUG'); + } + } + + if (is_null($instance)) { + $instance = new IMP_Search(); + } + + 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, $injector) + { + /* Only need to store the object if the object has changed. */ + if ($instance->changed) { + $_SESSION['imp']['search'] = serialize($instance); + } + } + +} diff --git a/imp/lib/Injector/Factory/Sentmail.php b/imp/lib/Injector/Factory/Sentmail.php new file mode 100644 index 000000000..a31505822 --- /dev/null +++ b/imp/lib/Injector/Factory/Sentmail.php @@ -0,0 +1,51 @@ + + * @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/) + * + * 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_Sentmail +{ + /** + * Return the IMP_Sentmail instance. + * + * @return IMP_Sentmail The singleton instance. + */ + public function create(Horde_Injector $injector) + { + $driver = empty($GLOBALS['conf']['sentmail']['driver']) + ? 'Null' + : $GLOBALS['conf']['sentmail']['driver']; + $params = Horde::getDriverConfig('sentmail', $driver); + + if (strcasecmp($driver, 'Sql') === 0) { + $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', 'sentmail'); + } elseif (strcasecmp($driver, 'None') === 0) { + $driver = 'Null'; + } + + return IMP_Sentmail::factory($driver, $params); + } + +} 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'); + } + +}