From: Michael M Slusarz Date: Wed, 14 Apr 2010 10:45:08 +0000 (-0600) Subject: Use injector to load IMP_Compose X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4633493b31e06c9325168d48d9bd9cdf60490f44;p=horde.git Use injector to load IMP_Compose --- diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index 109e61ee6..a24153127 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -57,7 +57,7 @@ if (!$prefs->isLocked('default_identity') && isset($vars->identity)) { } /* Initialize the IMP_Compose:: object. */ -$imp_compose = IMP_Compose::singleton(); +$imp_compose = $injector->getInstance('IMP_Compose')->getOb(); /* Init IMP_Ui_Compose:: object. */ $imp_ui = new IMP_Ui_Compose(); diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 29b0b41e1..4227787fb 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -70,7 +70,7 @@ $save_sent_mail = $imp_imap->isReadOnly($sent_mail_folder) $compose_disable = !IMP::canCompose(); /* Initialize objects. */ -$imp_compose = IMP_Compose::singleton($vars->composeCache); +$imp_compose = $injector->getInstance('IMP_Compose')->getOb($vars->composeCache); $imp_ui = new IMP_Ui_Compose(); foreach (array_keys($display_hdrs) as $val) { diff --git a/imp/compose.php b/imp/compose.php index 69044c7c6..eb3729009 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -108,7 +108,7 @@ if ($readonly_sentmail) { } /* Initialize the IMP_Compose:: object. */ -$imp_compose = IMP_Compose::singleton($vars->composeCache); +$imp_compose = $injector->getInstance('IMP_Compose')->getOb($vars->composeCache); $imp_compose->pgpAttachPubkey((bool) $vars->pgp_attach_pubkey); $imp_compose->userLinkAttachments((bool) $vars->link_attachments); diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 8c51a812f..b66280b91 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -1067,7 +1067,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base */ public function cancelCompose() { - $imp_compose = IMP_Compose::singleton($this->_vars->imp_compose); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->imp_compose); $imp_compose->destroy('cancel'); return true; @@ -1085,7 +1085,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base */ public function deleteDraft() { - IMP_Compose::singleton($this->_vars->imp_compose)->destroy('cancel'); + $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->imp_compose)->destroy('cancel'); return true; } @@ -1103,7 +1103,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base public function deleteAttach() { if (isset($this->_vars->atc_indices)) { - $imp_compose = IMP_Compose::singleton($this->_vars->imp_compose); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->imp_compose); foreach ($imp_compose->deleteAttachment($this->_vars->atc_indices) as $val) { $GLOBALS['notification']->push(sprintf(_("Deleted attachment \"%s\"."), Horde_Mime::decode($val)), 'horde.success'); } @@ -1287,7 +1287,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base */ public function addAttachment() { - $imp_compose = IMP_Compose::singleton($this->_vars->composeCache); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->composeCache); $result = new stdClass; $result->action = 'addAttachment'; @@ -1445,7 +1445,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base $result->success = 1; try { - $imp_compose = IMP_Compose::singleton($this->_vars->redirect_composeCache); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->redirect_composeCache); $imp_compose->sendRedirectMessage($this->_vars->redirect_to); $result->mbox = $imp_compose->getMetadata('mailbox'); @@ -1523,7 +1523,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base } $headers['subject'] = $this->_vars->subject; - $imp_compose = IMP_Compose::singleton($this->_vars->composeCache); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->composeCache); return array($result, $imp_compose, $headers, $identity); } @@ -1533,7 +1533,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base */ protected function _initCompose() { - $imp_compose = IMP_Compose::singleton($this->_vars->imp_compose); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->imp_compose); if (!($imp_contents = $imp_compose->getContentsOb())) { $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid); $i = each($indices); diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 0288e4916..ef42dc078 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -76,8 +76,7 @@ class IMP_Application extends Horde_Registry_Application { if (($e->getCode() == Horde_Registry::AUTH_FAILURE) && Horde_Util::getFormData('composeCache')) { - $imp_compose = IMP_Compose::singleton(); - $imp_compose->sessionExpireDraft(); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb()->sessionExpireDraft(); } } @@ -93,6 +92,7 @@ class IMP_Application extends Horde_Registry_Application { /* Add IMP-specific binders. */ $binders = array( + 'IMP_Compose' => new IMP_Injector_Binder_Compose(), 'IMP_Contents' => new IMP_Injector_Binder_Contents(), 'IMP_Crypt_Pgp' => new IMP_Injector_Binder_Pgp(), 'IMP_Crypt_Smime' => new IMP_Injector_Binder_Smime(), diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index fd02805f1..6b65757a5 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -498,8 +498,7 @@ class IMP_Auth } /* Check for drafts due to session timeouts. */ - $imp_compose = IMP_Compose::singleton(); - $imp_compose->recoverSessionExpireDraft(); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb()->recoverSessionExpireDraft(); self::_logMessage('login', 'NOTICE'); } diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index a589804a4..edf85f98c 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -23,13 +23,6 @@ class IMP_Compose const VFS_DRAFTS_PATH = '.horde/imp/drafts'; /** - * Singleton instances. - * - * @var array - */ - static protected $_instances = array(); - - /** * The cached attachment data. * * @var array @@ -87,36 +80,11 @@ class IMP_Compose protected $_modified = false; /** - * Attempts to return a reference to a concrete IMP_Compose instance. - * - * If an IMP_Cacheid object exists with the given cacheid, recreate that - * that object. Else, create a new instance. - * - * @param string $cacheid The cache ID string. - * - * @return IMP_Compose The IMP_Compose object. - */ - static public function singleton($cacheid = null) - { - if (!empty($cacheid) && !isset(self::$_instances[$cacheid])) { - $obs = $GLOBALS['injector']->getInstance('Horde_SessionObjects'); - self::$_instances[$cacheid] = $obs->query($cacheid); - } - - if (empty($cacheid) || empty(self::$_instances[$cacheid])) { - $cacheid = empty($cacheid) ? uniqid(mt_rand()) : $cacheid; - self::$_instances[$cacheid] = new self($cacheid); - } - - return self::$_instances[$cacheid]; - } - - /** * Constructor. * * @param string $cacheid The cache ID string. */ - protected function __construct($cacheid) + public function __construct($cacheid) { $this->_cacheid = $cacheid; $this->__wakeup(); diff --git a/imp/lib/Injector/Binder/Compose.php b/imp/lib/Injector/Binder/Compose.php new file mode 100644 index 000000000..34188cb8f --- /dev/null +++ b/imp/lib/Injector/Binder/Compose.php @@ -0,0 +1,29 @@ + + * @package IMP + */ +class IMP_Injector_Binder_Compose implements Horde_Injector_Binder +{ + /** + */ + public function create(Horde_Injector $injector) + { + return new IMP_Injector_Factory_Compose($injector); + } + + /** + */ + public function equals(Horde_Injector_Binder $binder) + { + return false; + } + +} diff --git a/imp/lib/Injector/Factory/Compose.php b/imp/lib/Injector/Factory/Compose.php new file mode 100644 index 000000000..1563cb250 --- /dev/null +++ b/imp/lib/Injector/Factory/Compose.php @@ -0,0 +1,78 @@ + + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + */ + +/** + * A Horde_Injector:: based IMP_Compose:: 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. + * + * @category Horde + * @package IMP + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + */ +class IMP_Injector_Factory_Compose +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return the Horde_Compose:: instance. + * + * @param string $cacheid The cache ID string. + * + * @return IMP_Compose The singleton compose instance. + * @throws IMP_Exception + */ + public function getOb($cacheid = null) + { + if (empty($cacheid)) { + $cacheid = uniqid(mt_rand()); + } elseif (!isset($this->_instances[$cacheid])) { + $obs = $GLOBALS['injector']->getInstance('Horde_SessionObjects'); + $this->_instances[$cacheid] = $obs->query($cacheid); + } + + if (empty($this->_instances[$cacheid])) { + $this->_instances[$cacheid] = new IMP_Compose($cacheid); + } + + return $this->_instances[$cacheid]; + } + +} diff --git a/imp/lib/Message.php b/imp/lib/Message.php index a04b1a956..777ea390d 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -319,7 +319,6 @@ class IMP_Message $subject = $imp_headers->getValue('subject'); /* Extract the message body. */ - $imp_compose = IMP_Compose::singleton(); $mime_message = $imp_contents->getMIMEMessage(); $body_id = $imp_contents->findBody(); $body_part = $mime_message->getPart($body_id); diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index df2127486..654c56bad 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -109,7 +109,7 @@ class IMP_Spam } if (!isset($imp_compose)) { - $imp_compose = IMP_Compose::singleton(); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb(); try { $from_line = $GLOBALS['injector']->getInstance('IMP_Identity')->getFromLine(); } catch (Horde_Exception $e) { diff --git a/imp/lib/Views/Compose.php b/imp/lib/Views/Compose.php index 1ae6c1362..a97b4e5e1 100644 --- a/imp/lib/Views/Compose.php +++ b/imp/lib/Views/Compose.php @@ -41,7 +41,7 @@ class IMP_Views_Compose if (empty($args['composeCache'])) { $composeCache = null; } else { - $imp_compose = IMP_Compose::singleton($args['composeCache']); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($args['composeCache']); $composeCache = $args['composeCache']; } diff --git a/imp/view.php b/imp/view.php index 2d548c1fd..a590648c0 100644 --- a/imp/view.php +++ b/imp/view.php @@ -55,7 +55,7 @@ Horde_Registry::appInit('imp', array( * message data. Rather, we must use the IMP_Compose object to get the * necessary data for Horde_Mime_Part. */ if ($vars->actionID == 'compose_attach_preview') { - $imp_compose = IMP_Compose::singleton($vars->composeCache); + $imp_compose = $injector->getInstance('IMP_Compose')->getOb($vars->composeCache); $mime = $imp_compose->buildAttachment($vars->id); $mime->setMimeId($vars->id);