}
/* 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();
$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) {
}
/* 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);
*/
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;
*/
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;
}
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');
}
*/
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';
$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');
}
$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);
}
*/
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);
{
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();
}
}
{
/* 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(),
}
/* 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');
}
const VFS_DRAFTS_PATH = '.horde/imp/drafts';
/**
- * Singleton instances.
- *
- * @var array
- */
- static protected $_instances = array();
-
- /**
* The cached attachment data.
*
* @var array
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();
--- /dev/null
+<?php
+/**
+ * Binder for IMP_Compose::.
+ *
+ * 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 <slusarz@horde.org>
+ * @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;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based IMP_Compose:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package IMP
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @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 <slusarz@horde.org>
+ * @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];
+ }
+
+}
$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);
}
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) {
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'];
}
* 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);