$result->ViewPort = $this->_viewPortData(true);
} else {
$result->ViewPort = new stdClass;
- $result->ViewPort->updatecacheid = IMP_Mailbox::singleton($this->_vars->view)->getCacheID($this->_vars->view);
+ $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($this->_vars->view)->getCacheID($this->_vars->view);
$result->ViewPort->view = $this->_vars->view;
}
return $result;
$result = $this->_checkUidvalidity($result);
} elseif (!$change) {
/* Only update cacheid info if it changed. */
- $cacheid = IMP_Mailbox::singleton($this->_vars->view)->getCacheID($this->_vars->view);
+ $cacheid = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($this->_vars->view)->getCacheID($this->_vars->view);
if ($cacheid != $this->_vars->cacheid) {
$result->ViewPort = new stdClass;
$result->ViewPort->updatecacheid = $cacheid;
$result->ViewPort = $this->_viewPortData(true);
} else {
$result->ViewPort = new stdClass;
- $result->ViewPort->updatecacheid = IMP_Mailbox::singleton($this->_vars->view)->getCacheID($this->_vars->view);
+ $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($this->_vars->view)->getCacheID($this->_vars->view);
$result->ViewPort->view = $this->_vars->view;
}
}
}
- return (IMP_Mailbox::singleton($this->_vars->view)->getCacheID($this->_vars->view) != $this->_vars->cacheid);
+ return ($GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($this->_vars->view)->getCacheID($this->_vars->view) != $this->_vars->cacheid);
}
/**
'IMP_Folder' => new IMP_Injector_Binder_Folder(),
'IMP_Identity' => new IMP_Injector_Binder_Identity(),
'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(),
+ 'IMP_Mailbox' => new IMP_Injector_Binder_Mailbox(),
'IMP_Quota' => new IMP_Injector_Binder_Quota(),
'IMP_Sentmail' => new IMP_Injector_Binder_Sentmail()
);
--- /dev/null
+<?php
+/**
+ * Binder for IMP_Mailbox::.
+ *
+ * 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_Mailbox implements Horde_Injector_Binder
+{
+ /**
+ */
+ public function create(Horde_Injector $injector)
+ {
+ return new IMP_Injector_Factory_Mailbox($injector);
+ }
+
+ /**
+ */
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based IMP_Mailbox:: 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_Mailbox:: 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_Mailbox
+{
+ /**
+ * 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_Mailbox:: instance.
+ *
+ * @param string $mailbox The mailbox name.
+ * @param string $msgmbox The mailbox name of the current index.
+ * @param integer $uid The message UID of the current index.
+ *
+ * @return IMP_Mailbox The singleton mailbox instance.
+ * @throws IMP_Exception
+ */
+ public function getOb($mailbox, $msgmbox = null, $uid = null)
+ {
+ $uid = (is_null($msgmbox) || is_null($uid))
+ ? null
+ : $uid . IMP::IDX_SEP . $msgmbox;
+
+ if (!isset($this->_instances[$mailbox])) {
+ $this->_instances[$mailbox] = new IMP_Mailbox($mailbox, $uid);
+ } elseif (!is_null($uid)) {
+ $this->_instances[$mailbox]->setIndex($uid);
+ }
+
+ return $this->_instances[$mailbox];
+ }
+
+}
class IMP_Mailbox
{
/**
- * Singleton instances
- *
- * @var array
- */
- protected static $_instances = array();
-
- /**
* The mailbox to work with.
*
* @var string
protected $_changed = false;
/**
- * Attempts to return a reference to a concrete instance.
- * It will only create a new instance if no instance with the same
- * parameters currently exists.
- *
- * @param string $mailbox See constructor.
- * @param string $uid UID string (UID . IMP::IDX_SEP . Mailbox).
- *
- * @return IMP_Mailbox The created instance.
- */
- static public function singleton($mailbox, $uid = null)
- {
- if (!isset(self::$_instances[$mailbox])) {
- self::$_instances[$mailbox] = new self($mailbox, $uid);
- } elseif (!is_null($uid)) {
- self::$_instances[$mailbox]->setIndex($uid);
- }
-
- return self::$_instances[$mailbox];
- }
-
- /**
* Constructor.
*
* @param string $mailbox The mailbox to work with.
* @param string $uid UID string (UID . IMP::IDX_SEP . Mailbox).
*/
- protected function __construct($mailbox, $uid = null)
+ public function __construct($mailbox, $uid = null)
{
$this->_mailbox = $mailbox;
$this->_searchmbox = $GLOBALS['imp_search']->isSearchMbox($mailbox);
try {
$GLOBALS['imp_imap']->ob()->copy($mbox, $targetMbox, array('ids' => $msgIndices, 'move' => $imap_move));
- $imp_mailbox = IMP_Mailbox::singleton($mbox);
+ $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox);
if (($action == 'move') && $imp_mailbox->isBuilt()) {
$imp_mailbox->removeMsgs(array($mbox => $msgIndices));
}
try {
$GLOBALS['imp_imap']->ob()->copy($mbox, $trash, array('ids' => $msgIndices, 'move' => true));
- $imp_mailbox = IMP_Mailbox::singleton($mbox);
+ $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox);
if ($imp_mailbox->isBuilt()) {
$imp_mailbox->removeMsgs(array($mbox => $msgIndices));
}
$this->delete($indices, array('nuke' => true, 'keeplog' => true));
- $imp_mailbox = IMP_Mailbox::singleton($mbox);
+ $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox);
$imp_mailbox->setIndex(reset($uid));
/* We need to replace the old index in the query string with the
try {
$update_list[$key] = $GLOBALS['imp_imap']->ob()->expunge($key, array('ids' => is_array($val) ? $val : array(), 'list' => $msg_list));
- $imp_mailbox = IMP_Mailbox::singleton($key);
+ $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($key);
if ($imp_mailbox->isBuilt()) {
$imp_mailbox->removeMsgs(is_array($val) ? array($key => $val) : true);
}
}
/* Generate the sorted mailbox list now. */
- $imp_mailbox = IMP_Mailbox::singleton($mbox);
+ $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox);
$sorted_list = $imp_mailbox->getSortedList();
$msgcount = count($sorted_list['s']);
}
/* Build the list of messages in the mailbox. */
-$imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox']);
+$imp_mailbox = $injector->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox']);
$pageOb = $imp_mailbox->buildMailboxPage($vars->p, $vars->s);
/* Generate page title. */
}
/* Build the list of messages in the mailbox. */
-$imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox']);
+$imp_mailbox = $injector->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox']);
$pageOb = $imp_mailbox->buildMailboxPage(Horde_Util::getFormData('page'), $start);
$show_preview = $prefs->getValue('preview_enabled');
$vars = Horde_Variables::getDefaultVariables();
/* Make sure we have a valid index. */
-$imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox'], $imp_mbox['uid'] . IMP::IDX_SEP . $imp_mbox['thismailbox']);
+$imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox'], $imp_mbox['thismailbox'], $imp_mbox['uid']);
if (!$imp_mailbox->isValidIndex(false)) {
header('Location: ' . IMP::generateIMPUrl('mailbox-mimp.php', $imp_mbox['mailbox'])->setRaw(true)->add('a', 'm'));
exit;
}
/* Make sure we have a valid index. */
-$imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox'], $imp_mbox['uid'] . IMP::IDX_SEP . $imp_mbox['thismailbox']);
+$imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox'], $imp_mbox['thismailbox'], $imp_mbox['uid']);
if (!$imp_mailbox->isValidIndex(false)) {
_returnToMailbox(null, 'message_missing');
require IMP_BASE . '/mailbox.php';
}
/* Obtain some information describing the mailbox state. */
-$imp_mailbox = IMP_Mailbox::singleton($mailbox);
+$imp_mailbox = $injector->getInstance('IMP_Mailbox')->getOb($mailbox);
$total_num = $imp_mailbox->getMessageCount();
$unseen_num = ($imp_search->isVINBOXFolder($mailbox))
? $imp_mailbox->getMessageCount()
*/
$mode = Horde_Util::getFormData('mode', 'thread');
-$imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox'], $imp_mbox['uid'] . IMP::IDX_SEP . $imp_mbox['thismailbox']);
+$imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox'], $imp_mbox['thismailbox'], $imp_mbox['uid']);
$error = false;
if ($mode == 'thread') {