From: Michael M Slusarz Date: Wed, 26 Jan 2011 19:20:45 +0000 (-0700) Subject: Move app Injector/Factory to just Factory/ X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0b950af7b46d5cb5998ddb74a7e6d97f4846355c;p=horde.git Move app Injector/Factory to just Factory/ Mirrors use of Horde_Core_Factory. Additionally, these factory injectors don't extend any Horde_Injector class. --- diff --git a/ansel/lib/Application.php b/ansel/lib/Application.php index c1f16b94e..4cb6e8e50 100644 --- a/ansel/lib/Application.php +++ b/ansel/lib/Application.php @@ -66,12 +66,12 @@ class Ansel_Application extends Horde_Registry_Application } $factories = array( - 'Ansel_Styles' => array('Ansel_Injector_Factory_Styles', 'create'), - 'Ansel_Faces' => array('Ansel_Injector_Factory_Faces', 'create'), - 'Ansel_Storage' => array('Ansel_Injector_Factory_Storage', 'create'), + 'Ansel_Styles' => 'Ansel_Factory_Styles', + 'Ansel_Faces' => 'Ansel_Factory_Faces', + 'Ansel_Storage' => 'Ansel_Factory_Storage', ); foreach ($factories as $interface => $v) { - $GLOBALS['injector']->bindFactory($interface, $v[0], $v[1]); + $GLOBALS['injector']->bindFactory($interface, $v, 'create'); } // Create db, share, and vfs instances. diff --git a/ansel/lib/Factory/Faces.php b/ansel/lib/Factory/Faces.php new file mode 100644 index 000000000..4d013dd5b --- /dev/null +++ b/ansel/lib/Factory/Faces.php @@ -0,0 +1,21 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Ansel + */ +class Ansel_Factory_Faces +{ + public function create (Horde_Injector $injector) + { + $driver = $GLOBALS['conf']['faces']['driver']; + $params = $GLOBALS['conf']['faces']; + $class_name = 'Ansel_Faces_' . ucfirst($driver); + + return new $class_name($params); + } + +} diff --git a/ansel/lib/Factory/Storage.php b/ansel/lib/Factory/Storage.php new file mode 100644 index 000000000..fca1a53b6 --- /dev/null +++ b/ansel/lib/Factory/Storage.php @@ -0,0 +1,53 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Ansel + */ +class Ansel_Factory_Storage +{ + /** + * Array of already instantiated instances + * + * @var array + */ + private $_instances = array(); + + /** + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor + * + * @param Horde_Injector $injector + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return an Ansel_Storage instance scoped for the current Ansel scope. + * Scope is determined by the current value of Ansel_Config::scope + * + * @return Ansel_Storage + */ + public function create() + { + $scope = $this->_injector->getInstance('Ansel_Config')->get('scope'); + if (empty($this->_instances[$scope])) { + $this->_instances[$scope] = new Ansel_Storage($this->_injector->getInstance('Horde_Core_Factory_Share')->create($scope, 'Sql')); + } + + return $this->_instances[$scope]; + } + +} diff --git a/ansel/lib/Factory/Styles.php b/ansel/lib/Factory/Styles.php new file mode 100644 index 000000000..72c012950 --- /dev/null +++ b/ansel/lib/Factory/Styles.php @@ -0,0 +1,46 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Ansel + */ +class Ansel_Factory_Styles +{ + public function create (Horde_Injector $injector) + { + /* Brings in the $styles array in this scope only */ + $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); + + /* No prettythumbs allowed at all by admin choice */ + if (empty($GLOBALS['conf']['image']['prettythumbs'])) { + $test = $styles; + foreach ($test as $key => $style) { + if ($style['thumbstyle'] != 'Thumb') { + unset($styles[$key]); + } + } + } + + /* Check if the browser / server has png support */ + if ($GLOBALS['browser']->hasQuirk('png_transparency') || + $GLOBALS['conf']['image']['type'] != 'png') { + + $test = $styles; + foreach ($test as $key => $style) { + if (!empty($style['requires_png'])) { + if (!empty($style['fallback'])) { + $styles[$key] = $styles[$style['fallback']]; + } else { + unset($styles[$key]); + } + } + } + } + + return $styles; + } + +} diff --git a/ansel/lib/Injector/Factory/Faces.php b/ansel/lib/Injector/Factory/Faces.php deleted file mode 100644 index 513c676e2..000000000 --- a/ansel/lib/Injector/Factory/Faces.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package Ansel - */ -class Ansel_Injector_Factory_Faces -{ - public function create (Horde_Injector $injector) - { - $driver = $GLOBALS['conf']['faces']['driver']; - $params = $GLOBALS['conf']['faces']; - $class_name = 'Ansel_Faces_' . ucfirst($driver); - - return new $class_name($params); - } - -} \ No newline at end of file diff --git a/ansel/lib/Injector/Factory/Storage.php b/ansel/lib/Injector/Factory/Storage.php deleted file mode 100644 index c22cfb3b7..000000000 --- a/ansel/lib/Injector/Factory/Storage.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package Ansel - */ -class Ansel_Injector_Factory_Storage -{ - /** - * Array of already instantiated instances - * - * @var array - */ - private $_instances = array(); - - /** - * - * @var Horde_Injector - */ - private $_injector; - - /** - * Constructor - * - * @param Horde_Injector $injector - */ - public function __construct(Horde_Injector $injector) - { - $this->_injector = $injector; - } - - /** - * Return an Ansel_Storage instance scoped for the current Ansel scope. - * Scope is determined by the current value of Ansel_Config::scope - * - * @return Ansel_Storage - */ - public function create() - { - $scope = $this->_injector->getInstance('Ansel_Config')->get('scope'); - if (empty($this->_instances[$scope])) { - $this->_instances[$scope] = new Ansel_Storage($this->_injector->getInstance('Horde_Core_Factory_Share')->create($scope, 'Sql')); - } - - return $this->_instances[$scope]; - } - -} diff --git a/ansel/lib/Injector/Factory/Styles.php b/ansel/lib/Injector/Factory/Styles.php deleted file mode 100644 index d4527cdd7..000000000 --- a/ansel/lib/Injector/Factory/Styles.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package Ansel - */ -class Ansel_Injector_Factory_Styles -{ - public function create (Horde_Injector $injector) - { - /* Brings in the $styles array in this scope only */ - $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); - - /* No prettythumbs allowed at all by admin choice */ - if (empty($GLOBALS['conf']['image']['prettythumbs'])) { - $test = $styles; - foreach ($test as $key => $style) { - if ($style['thumbstyle'] != 'Thumb') { - unset($styles[$key]); - } - } - } - - /* Check if the browser / server has png support */ - if ($GLOBALS['browser']->hasQuirk('png_transparency') || - $GLOBALS['conf']['image']['type'] != 'png') { - - $test = $styles; - foreach ($test as $key => $style) { - if (!empty($style['requires_png'])) { - if (!empty($style['fallback'])) { - $styles[$key] = $styles[$style['fallback']]; - } else { - unset($styles[$key]); - } - } - } - } - - return $styles; - } - -} \ No newline at end of file diff --git a/hermes/lib/Application.php b/hermes/lib/Application.php index f3df91c6b..d1ca70c55 100644 --- a/hermes/lib/Application.php +++ b/hermes/lib/Application.php @@ -51,7 +51,7 @@ class Hermes_Application extends Horde_Registry_Application */ protected function _init() { - $GLOBALS['injector']->bindFactory('Hermes_Driver', 'Hermes_Injector_Factory_Driver', 'create'); + $GLOBALS['injector']->bindFactory('Hermes_Driver', 'Hermes_Factory_Driver', 'create'); } /** diff --git a/hermes/lib/Factory/Driver.php b/hermes/lib/Factory/Driver.php new file mode 100644 index 000000000..ffa5b1d26 --- /dev/null +++ b/hermes/lib/Factory/Driver.php @@ -0,0 +1,51 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Hermes + */ +class Hermes_Factory_Driver +{ + /** + * + * @var array + */ + private $_instances = array(); + + /** + * + * @var Horde_Injector + */ + private $_injector; + + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return an Hermes_Storage instance. + * + * @return Ansel_Storage + */ + public function create() + { + $driver = $GLOBALS['conf']['storage']['driver']; + $signature = serialize(array($driver, $GLOBALS['conf']['storage']['params']['driverconfig'])); + if (empty($this->_instances[$signature])) { + if ($driver == 'sql' && $GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') { + $params = array('db_adapter' => $this->_injector->getInstance('Horde_Db_Adapter')); + } else { + throw new Horde_Exception('Using non-global db connection not yet supported.'); + } + $class = 'Hermes_Driver_' . Horde_String::ucfirst($driver); + $this->_instances[$signature] = new $class($params); + } + + return $this->_instances[$signature]; + } + +} diff --git a/hermes/lib/Injector/Factory/Driver.php b/hermes/lib/Injector/Factory/Driver.php deleted file mode 100644 index 46c55f70e..000000000 --- a/hermes/lib/Injector/Factory/Driver.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package Hermes - */ -class Hermes_Injector_Factory_Driver -{ - /** - * - * @var array - */ - private $_instances = array(); - - /** - * - * @var Horde_Injector - */ - private $_injector; - - public function __construct(Horde_Injector $injector) - { - $this->_injector = $injector; - } - - /** - * Return an Hermes_Storage instance. - * - * @return Ansel_Storage - */ - public function create() - { - $driver = $GLOBALS['conf']['storage']['driver']; - $signature = serialize(array($driver, $GLOBALS['conf']['storage']['params']['driverconfig'])); - if (empty($this->_instances[$signature])) { - if ($driver == 'sql' && $GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') { - $params = array('db_adapter' => $this->_injector->getInstance('Horde_Db_Adapter')); - } else { - throw new Horde_Exception('Using non-global db connection not yet supported.'); - } - $class = 'Hermes_Driver_' . Horde_String::ucfirst($driver); - $this->_instances[$signature] = new $class($params); - } - - return $this->_instances[$signature]; - } - -} diff --git a/imp/bin/query_imap_cache b/imp/bin/query_imap_cache index c135123ef..93c2e02fb 100755 --- a/imp/bin/query_imap_cache +++ b/imp/bin/query_imap_cache @@ -46,7 +46,7 @@ foreach ($options[0] as $val) { } } -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (is_null($server)) { /* Set first entry to 1, not 0. */ diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index de83f3d80..62c349ecd 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -62,7 +62,7 @@ if (!$prefs->isLocked('default_identity') && isset($vars->identity)) { } /* Init objects. */ -$imp_compose = $injector->getInstance('IMP_Injector_Factory_Compose')->create(); +$imp_compose = $injector->getInstance('IMP_Factory_Compose')->create(); $imp_ui = new IMP_Ui_Compose(); $show_editor = false; diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 16f5c8dd6..306a8f03a 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -64,7 +64,7 @@ $sent_mail_folder = $identity->getValue('sent_mail_folder'); /* Determine if mailboxes are readonly. */ $readonly_drafts = false; -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!empty($draft)) { $draft = IMP::folderPref($draft, true); $readonly_drafts = $imp_folder->exists($draft) && @@ -78,7 +78,7 @@ $save_sent_mail = ($imp_folder->exists($sent_mail_folder) && $imp_imap->isReadOn $compose_disable = !IMP::canCompose(); /* Initialize objects. */ -$imp_compose = $injector->getInstance('IMP_Injector_Factory_Compose')->create($vars->composeCache); +$imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($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 a878b8ca4..3a1c63d94 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -101,7 +101,7 @@ $compose_disable = !IMP::canCompose(); $imp_folder = $injector->getInstance('IMP_Folder'); $readonly_drafts = $readonly_sentmail = false; $draft = $prefs->getValue('drafts_folder'); -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!empty($draft)) { $draft = IMP::folderPref($draft, true); $readonly_drafts = $imp_folder->exists($draft) && @@ -114,7 +114,7 @@ if ($readonly_sentmail) { } /* Initialize the IMP_Compose:: object. */ -$imp_compose = $injector->getInstance('IMP_Injector_Factory_Compose')->create($vars->composeCache); +$imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($vars->composeCache); $imp_compose->pgpAttachPubkey((bool) $vars->pgp_attach_pubkey); $imp_compose->userLinkAttachments((bool) $vars->link_attachments); diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index 4d2ab828e..cea61efc8 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -651,7 +651,7 @@ class IMP_Hooks // // Requires the 'command' parameter to be defined in backends.php, // // which defines the quota reporting function to run on the SSH // // host. -// $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); +// $imap_ob = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); // $host = $imap_ob->ob->getParam('hostspec'); // $user = $params['host']; // $pass = $imap_ob->ob->getParam('password'); diff --git a/imp/folders-mimp.php b/imp/folders-mimp.php index 927f99ad9..f12dc5ed0 100644 --- a/imp/folders-mimp.php +++ b/imp/folders-mimp.php @@ -22,7 +22,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; Horde_Registry::appInit('imp', array('impmode' => 'mimp')); /* Redirect back to the mailbox if folder use is not allowed. */ -if (!$injector->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { +if (!$injector->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { $notification->push(_("Folder use is not enabled."), 'horde.error'); Horde::url('mailbox-mimp.php', true)->redirect(); } diff --git a/imp/folders.php b/imp/folders.php index 9fd5f5ef3..061e0bd06 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -23,7 +23,7 @@ Horde_Registry::appInit('imp', array( Horde::addScriptFile('folders.js', 'imp'); /* Redirect back to the mailbox if folder use is not allowed. */ -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!$imp_imap->allowFolders()) { $notification->push(_("Folder use is not enabled."), 'horde.error'); Horde::url('mailbox.php', true)->redirect(); @@ -251,7 +251,7 @@ case 'folders_empty_mailbox_confirm': } try { - $elt_info = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->status($val, Horde_Imap_Client::STATUS_MESSAGES); + $elt_info = $injector->getInstance('IMP_Factory_Imap')->create()->status($val, Horde_Imap_Client::STATUS_MESSAGES); } catch (Horde_Imap_Client_Exception $e) { $elt_info = null; } @@ -427,7 +427,7 @@ if (!empty($imaptree->recent)) { /* Open the mailbox R/W so we ensure the 'recent' flags are cleared from * the current mailbox. */ foreach ($imaptree->recent as $mbox => $nm) { - $injector->getInstance('IMP_Injector_Factory_Imap')->create()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE); + $injector->getInstance('IMP_Factory_Imap')->create()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE); } IMP::newmailAlerts($imaptree->recent); diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 0d1f2d37a..8080c4ebb 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -500,7 +500,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application if ($this->_vars->add) { $imptree->addPollList($this->_vars->mbox); try { - if ($info = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->status($this->_vars->mbox, Horde_Imap_Client::STATUS_UNSEEN)) { + if ($info = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->status($this->_vars->mbox, Horde_Imap_Client::STATUS_UNSEEN)) { $result->poll = array($this->_vars->mbox => intval($info['unseen'])); } } catch (Horde_Imap_Client_Exception $e) {} @@ -739,7 +739,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application $result->ViewPort = $this->_viewPortData(true); } else { $result->ViewPort = new stdClass; - $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view); + $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view); $result->ViewPort->view = $this->_vars->view; } @@ -986,7 +986,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application $result = $this->_checkUidvalidity($result); } elseif (!$change) { /* Only update cacheid info if it changed. */ - $cacheid = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view); + $cacheid = $GLOBALS['injector']->getInstance('IMP_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view); if ($cacheid != $this->_vars->cacheid) { $result->ViewPort = new stdClass; $result->ViewPort->updatecacheid = $cacheid; @@ -1272,7 +1272,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application */ public function cancelCompose() { - $imp_compose = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->imp_compose); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->_vars->imp_compose); $imp_compose->destroy('cancel'); return true; @@ -1325,7 +1325,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application */ public function deleteDraft() { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->imp_compose)->destroy('cancel'); + $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->_vars->imp_compose)->destroy('cancel'); return true; } @@ -1343,7 +1343,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application public function deleteAttach() { if (isset($this->_vars->atc_indices)) { - $imp_compose = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->imp_compose); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->_vars->imp_compose); foreach ($this->_vars->atc_indices as $val) { $GLOBALS['notification']->push(sprintf(_("Deleted attachment \"%s\"."), Horde_Mime::decode($imp_compose[$val]['part']->getName(true))), 'horde.success'); unset($imp_compose[$val]); @@ -1494,7 +1494,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application } try { - $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($this->_vars->folder, array( + $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($this->_vars->folder, array( Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => false)) ), array('ids' => array($this->_vars->uid))); } catch (Horde_Imap_Client_Exception $e) { @@ -1578,7 +1578,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application */ public function addAttachment() { - $imp_compose = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->composeCache); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->_vars->composeCache); $result = new stdClass; $result->action = 'addAttachment'; @@ -1783,7 +1783,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application $result->success = 1; try { - $imp_compose = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->composeCache); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->_vars->composeCache); $imp_compose->sendRedirectMessage($this->_vars->redirect_to); $result->mbox = $imp_compose->getMetadata('mailbox'); @@ -1864,7 +1864,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application if (is_null($mbox)) { $result = array(); - foreach ($GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->statusMultiple($imaptree->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) { + foreach ($GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->statusMultiple($imaptree->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) { $result[$key] = intval($val['unseen']); } return $result; @@ -1929,7 +1929,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application } $headers['subject'] = $this->_vars->subject; - $imp_compose = $injector->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->composeCache); + $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->_vars->composeCache); return array($result, $imp_compose, $headers, $identity); } @@ -1939,10 +1939,10 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application */ protected function _initCompose() { - $imp_compose = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($this->_vars->imp_compose); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->_vars->imp_compose); if (!($imp_contents = $imp_compose->getContentsOb())) { $imp_contents = $this->_vars->uid - ? $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($this->_vars->uid)) + ? $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($this->_vars->uid)) : null; } @@ -2007,7 +2007,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application protected function _checkUidvalidity($result = false) { try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->checkUidvalidity($this->_vars->view); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->checkUidvalidity($this->_vars->view); } catch (IMP_Exception $e) { if (!is_object($result)) { $result = new stdClass; @@ -2062,7 +2062,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application $result->ViewPort = $this->_viewPortData(true); } else { $result->ViewPort = new stdClass; - $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view); + $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view); $result->ViewPort->view = $this->_vars->view; } @@ -2103,7 +2103,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application * on the IMAP server (saves some STATUS calls). */ if (!is_null($rw)) { try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->openMailbox($this->_vars->view, $rw ? Horde_Imap_Client::OPEN_READWRITE : Horde_Imap_Client::OPEN_AUTO); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->openMailbox($this->_vars->view, $rw ? Horde_Imap_Client::OPEN_READWRITE : Horde_Imap_Client::OPEN_AUTO); } catch (Horde_Imap_Client_Exception $e) { if ($e->getCode() == Horde_Imap_Client_Exception::MAILBOX_NOOPEN) { $GLOBALS['notification']->push(sprintf(_("Could not open mailbox \"%s\"."), $this->_vars->view), 'horde.error'); @@ -2114,7 +2114,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application } } - return ($GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view) != $this->_vars->cacheid); + return ($GLOBALS['injector']->getInstance('IMP_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view) != $this->_vars->cacheid); } /** diff --git a/imp/lib/Api.php b/imp/lib/Api.php index e787edfc8..1afd38d05 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -88,7 +88,7 @@ class IMP_Api extends Horde_Registry_Api */ public function createFolder($folder) { - $fname = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->appendNamespace($folder); + $fname = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->appendNamespace($folder); return $GLOBALS['injector']->getInstance('IMP_Folder')->create($fname, $GLOBALS['prefs']->getValue('subscribe')) ? $fname : false; @@ -181,7 +181,7 @@ class IMP_Api extends Horde_Registry_Api */ public function server() { - $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imap_ob = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); return array( 'hostspec' => $imap_ob->ob->getParam('hostspec'), @@ -214,7 +214,7 @@ class IMP_Api extends Horde_Registry_Api */ public function imapOb() { - return $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->ob; + return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->ob; } /** diff --git a/imp/lib/Application.php b/imp/lib/Application.php index a4cb88bc4..b3342783d 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -86,7 +86,7 @@ class IMP_Application extends Horde_Registry_Application { if (($e->getCode() == Horde_Registry::AUTH_FAILURE) && Horde_Util::getFormData('composeCache')) { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create()->sessionExpireDraft(Horde_Variables::getDefaultVariables()); + $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create()->sessionExpireDraft(Horde_Variables::getDefaultVariables()); } } @@ -97,16 +97,16 @@ class IMP_Application extends Horde_Registry_Application { /* 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_Flags' => 'IMP_Injector_Factory_Flags', - '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' + 'IMP_AuthImap' => 'IMP_Factory_AuthImap', + 'IMP_Crypt_Pgp' => 'IMP_Factory_Pgp', + 'IMP_Crypt_Smime' => 'IMP_Factory_Smime', + 'IMP_Flags' => 'IMP_Factory_Flags', + 'IMP_Identity' => 'IMP_Factory_Identity', + 'IMP_Imap_Tree' => 'IMP_Factory_Imaptree', + 'IMP_Mail' => 'IMP_Factory_Mail', + 'IMP_Quota' => 'IMP_Factory_Quota', + 'IMP_Search' => 'IMP_Factory_Search', + 'IMP_Sentmail' => 'IMP_Factory_Sentmail' ); foreach ($factories as $key => $val) { @@ -162,7 +162,7 @@ class IMP_Application extends Horde_Registry_Application { /* Clean up dangling IMP_Compose objects. */ foreach (array_keys($GLOBALS['session']->get('imp', 'compose_cache', Horde_Session::TYPE_ARRAY)) as $key) { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create($key)->destroy('cancel'); + $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($key)->destroy('cancel'); } /* No need to keep Tree object in cache - it will be recreated next @@ -260,7 +260,7 @@ class IMP_Application extends Horde_Registry_Application $trash_folder = IMP::folderPref($trash_folder, true); if ($injector->getInstance('IMP_Search')->isVTrash($trash_folder) || - !$injector->getInstance('IMP_Injector_Factory_Imap')->create()->isReadOnly($trash_folder)) { + !$injector->getInstance('IMP_Factory_Imap')->create()->isReadOnly($trash_folder)) { $menu->addArray(array( 'class' => '__noselection', 'icon' => 'empty_trash.png', @@ -292,7 +292,7 @@ class IMP_Application extends Horde_Registry_Application )); } - if ($injector->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { + if ($injector->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { $menu->addArray(array( 'icon' => 'folders/folder.png', 'text' => _("_Folders"), diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 1e684f5c4..e78ce04bd 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -80,7 +80,7 @@ class IMP_Auth $credentials['server'] = self::getAutoLoginServer(); } - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create($credentials['server']); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create($credentials['server']); // Check for valid IMAP Client object. if (!$imp_imap->ob) { @@ -264,7 +264,7 @@ class IMP_Auth */ static protected function _canAutoLogin($server_key = null, $force = false) { - if (($servers = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->loadServerConfig()) === false) { + if (($servers = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->loadServerConfig()) === false) { return false; } @@ -351,7 +351,7 @@ class IMP_Auth { global $browser, $conf, $injector, $prefs, $registry, $session; - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(null, true); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(null, true); $ptr = $imp_imap->loadServerConfig($session->get('imp', 'server_key')); if ($ptr === false) { throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED); @@ -487,7 +487,7 @@ class IMP_Auth } /* Check for drafts due to session timeouts. */ - $imp_compose = $injector->getInstance('IMP_Injector_Factory_Compose')->create()->recoverSessionExpireDraft(); + $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create()->recoverSessionExpireDraft(); self::_logMessage(true, $imp_imap); } diff --git a/imp/lib/Block/Newmail.php b/imp/lib/Block/Newmail.php index 4f69d6ce5..62acd0282 100644 --- a/imp/lib/Block/Newmail.php +++ b/imp/lib/Block/Newmail.php @@ -39,7 +39,7 @@ class IMP_Block_Newmail extends Horde_Block : $this->_params['msgs_shown']; try { - $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch('INBOX', array( + $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch('INBOX', array( Horde_Imap_Client::FETCH_ENVELOPE => true ), array('ids' => array_slice($indices, 0, $shown))); reset($fetch_ret); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 5a823a00c..c8d6e2560 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -219,7 +219,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator /* Add information necessary to log replies/forwards when finally * sent. */ if ($this->getMetadata('reply_type')) { - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); try { $imap_url = $imp_imap->getUtils()->createUrl(array( 'type' => $GLOBALS['session']->get('imp', 'protocol'), @@ -287,7 +287,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator /* Add the message to the mailbox. */ try { - $ids = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags))); + $ids = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags))); if ($old_uid) { $GLOBALS['injector']->getInstance('IMP_Message')->delete($old_uid, array('nuke' => true)); @@ -322,7 +322,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator global $injector, $prefs; try { - $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create($indices); + $contents = $injector->getInstance('IMP_Factory_Contents')->create($indices); } catch (IMP_Exception $e) { throw new IMP_Compose_Exception($e); } @@ -419,7 +419,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator } if ($val) { - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); $imap_url = $imp_imap->getUtils()->parseUrl(rtrim(ltrim($val, '<'), '>')); try { @@ -429,7 +429,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator // even though the server is the same. UIDVALIDITY should // catch any true server/backend changes. ($imp_imap->checkUidvalidity($imap_url['mailbox']) == $imap_url['uidvalidity']) && - $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($imap_url['mailbox'], $imap_url['uid']))) { + $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imap_url['mailbox'], $imap_url['uid']))) { $this->_metadata['mailbox'] = $imap_url['mailbox']; $this->_metadata['reply_type'] = $reply_type; $this->_metadata['uid'] = $imap_url['uid']; @@ -678,7 +678,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator } try { - $injector->getInstance('IMP_Injector_Factory_Imap')->create()->append($opts['sent_folder'], array(array('data' => $fcc, 'flags' => $flags))); + $injector->getInstance('IMP_Factory_Imap')->create()->append($opts['sent_folder'], array(array('data' => $fcc, 'flags' => $flags))); } catch (Horde_Imap_Client_Exception $e) { $notification->push(sprintf(_("Message sent successfully, but not saved to %s"), IMP::displayFolder($opts['sent_folder']))); $sent_saved = false; @@ -1381,7 +1381,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator $subject = $h->getValue('subject'); $header['subject'] = empty($subject) ? 'Re: ' - : 'Re: ' . $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getUtils()->getBaseSubject($subject, array('keepblob' => true)); + : 'Re: ' . $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getUtils()->getBaseSubject($subject, array('keepblob' => true)); $force = false; if (in_array($type, array('reply', 'reply_auto', '*'))) { @@ -1665,7 +1665,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator $header['subject'] = $h->getValue('subject'); if (!empty($header['subject'])) { - $subject = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getUtils()->getBaseSubject($header['subject'], array('keepblob' => true)); + $subject = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getUtils()->getBaseSubject($header['subject'], array('keepblob' => true)); $header['title'] = _("Forward") . ': ' . $subject; $header['subject'] = 'Fwd: ' . $subject; } else { @@ -1861,7 +1861,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator $attached = 0; foreach ($indices as $mbox => $idx) { ++$attached; - $contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); + $contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); $headerob = $contents->getHeaderOb(); $part = new Horde_Mime_Part(); @@ -1880,7 +1880,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator } else { $name = Horde_String::truncate($name, 80); } - return 'Fwd: ' . $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getUtils()->getBaseSubject($name, array('keepblob' => true)); + return 'Fwd: ' . $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getUtils()->getBaseSubject($name, array('keepblob' => true)); } return 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached); @@ -2753,7 +2753,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator public function getContentsOb() { return $this->getMetadata('reply_type') - ? $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($this->getMetadata('mailbox'), $this->getMetadata('uid'))) + ? $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($this->getMetadata('mailbox'), $this->getMetadata('uid'))) : null; } diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index 40ac98445..c9c0a149d 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -99,7 +99,7 @@ class IMP_Contents /* Get the Horde_Mime_Part object for the given UID. */ try { - $ret = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($this->_mailbox, array( + $ret = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($this->_mailbox, array( Horde_Imap_Client::FETCH_STRUCTURE => array('parse' => true) ), array('ids' => array($this->_uid))); } catch (Horde_Imap_Client_Exception $e) { @@ -153,7 +153,7 @@ class IMP_Contents } try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($this->_mailbox, array( + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($this->_mailbox, array( Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true, 'stream' => !empty($options['stream']))) ), array('ids' => array($this->_uid))); return $res[$this->_uid]['bodytext'][0]; @@ -212,7 +212,7 @@ class IMP_Contents } try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($this->_mailbox, $query, array('ids' => array($this->_uid))); + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($this->_mailbox, $query, array('ids' => array($this->_uid))); if (empty($options['mimeheaders'])) { if (!empty($res[$this->_uid]['bodypartdecode'][$id])) { $this->lastBodyPartDecode = $res[$this->_uid]['bodypartdecode'][$id]; @@ -250,7 +250,7 @@ class IMP_Contents } try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($this->_mailbox, array( + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($this->_mailbox, array( Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => true)), Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true, 'stream' => !empty($options['stream']))) ), array('ids' => array($this->_uid))); @@ -284,7 +284,7 @@ class IMP_Contents } try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($this->_mailbox, array( + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($this->_mailbox, array( Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => $parse, 'peek' => true)) ), array('ids' => array($this->_uid))); return $res[$this->_uid]['headertext'][0]; @@ -385,7 +385,7 @@ class IMP_Contents ? null : $options['type']; - $viewer = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MimeViewer')->create($mime_part, $this, $type); + $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($mime_part, $this, $type); switch ($mode) { case self::RENDER_FULL: @@ -678,7 +678,7 @@ class IMP_Contents if ($is_atc && $download_zip && ($part['bytes'] > 204800)) { - $viewer = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MimeViewer')->create($mime_part, $this, $mime_type); + $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($mime_part, $this, $mime_type); if (!$viewer->getMetadata('compressed')) { $part['download_zip'] = $this->linkView($mime_part, 'download_attach', null, array('class' => 'iconImg downloadZipAtc', 'dload' => true, 'jstext' => sprintf(_("Download %s in .zip Format"), $mime_part->getDescription(true)), 'params' => array('zip' => 1))); } @@ -896,7 +896,7 @@ class IMP_Contents $last_id = null; $mime_part = $this->getMIMEPart($id, array('nocontents' => true)); - $viewer = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MimeViewer')->create($mime_part, $this); + $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($mime_part, $this); if ($viewer->embeddedMimeParts()) { $mime_part = $this->getMIMEPart($id); $viewer->setMIMEPart($mime_part); @@ -931,7 +931,7 @@ class IMP_Contents if (!is_object($part)) { $part = $this->getMIMEPart($part, array('nocontents' => true)); } - $viewer = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MimeViewer')->create($part, $this, $type); + $viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($part, $this, $type); if ($mask & self::RENDER_INLINE_AUTO) { $mask |= self::RENDER_INLINE | self::RENDER_INFO; diff --git a/imp/lib/Factory/AuthImap.php b/imp/lib/Factory/AuthImap.php new file mode 100644 index 000000000..8cf74770b --- /dev/null +++ b/imp/lib/Factory/AuthImap.php @@ -0,0 +1,62 @@ + + * @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_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.'); + } + + $aparams = $GLOBALS['session']->get('imp', 'imap_admin', Horde_Session::TYPE_ARRAY); + + $params = array_merge( + $params, + (isset($aparams['params']) ? $aparams['params'] : array()), + 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/Factory/Compose.php b/imp/lib/Factory/Compose.php new file mode 100644 index 000000000..5a5f7fadf --- /dev/null +++ b/imp/lib/Factory/Compose.php @@ -0,0 +1,112 @@ + + * @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 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. + * + * @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_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; + + register_shutdown_function(array($this, 'shutdown')); + } + + /** + * Return the IMP_Compose:: instance. + * + * @param string $cacheid The cache ID string. + * + * @return IMP_Compose The singleton compose instance. + * @throws IMP_Exception + */ + public function create($cacheid = null) + { + if (empty($cacheid)) { + $cacheid = strval(new Horde_Support_Randomid()); + } elseif (!isset($this->_instances[$cacheid])) { + $this->_instances[$cacheid] = $GLOBALS['session']->retrieve($cacheid); + } + + if (empty($this->_instances[$cacheid])) { + $this->_instances[$cacheid] = new IMP_Compose($cacheid); + } + + return $this->_instances[$cacheid]; + } + + /** + * Tasks to perform on shutdown. + */ + public function shutdown() + { + global $session; + + $cache = $session->get('imp', 'compose_cache', Horde_Session::TYPE_ARRAY); + $changed = false; + + foreach ($this->_instances as $key => $val) { + switch ($val->changed) { + case 'changed': + $val->changed = ''; + $session->store($val, false, $key); + $cache[$key] = 1; + $changed = true; + break; + + case 'deleted': + unset($cache[$key]); + $session->purge($key); + $changed = true; + break; + } + + } + + if ($changed) { + $session->set('imp', 'compose_cache', $cache); + } + } + +} diff --git a/imp/lib/Factory/Contents.php b/imp/lib/Factory/Contents.php new file mode 100644 index 000000000..51610079a --- /dev/null +++ b/imp/lib/Factory/Contents.php @@ -0,0 +1,56 @@ + + * @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 IMP_Contents:: 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_Factory_Contents +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * Return the IMP_Contents:: instance. + * + * @param IMP_Indices $indices An indices object. + * + * @return IMP_Contents The singleton contents instance. + * @throws IMP_Exception + */ + public function create($indices) + { + $key = strval($indices); + + if (!isset($this->_instances[$key])) { + $this->_instances[$key] = new IMP_Contents($indices); + } + + return $this->_instances[$key]; + } + +} diff --git a/imp/lib/Factory/Flags.php b/imp/lib/Factory/Flags.php new file mode 100644 index 000000000..e454465a0 --- /dev/null +++ b/imp/lib/Factory/Flags.php @@ -0,0 +1,66 @@ + + * @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_Flags 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_Factory_Flags +{ + /** + * Return the IMP_Flags instance. + * + * @return IMP_Flags The singleton instance. + */ + public function create(Horde_Injector $injector) + { + try { + $instance = $GLOBALS['session']->get('imp', 'flags'); + } catch (Exception $e) { + Horde::logMessage('Could not unserialize stored IMP_Flags object.', 'DEBUG'); + $instance = null; + } + + if (is_null($instance)) { + $instance = new IMP_Flags(); + } + + register_shutdown_function(array($this, 'shutdown'), $instance); + + return $instance; + } + + /** + * Store serialized version of object in the current session. + * + * @param IMP_Flags $instance Flags object. + */ + public function shutdown($instance) + { + /* Only need to store the object if the object has changed. */ + if ($instance->changed) { + $GLOBALS['session']->set('imp', 'flags', $instance); + } + } + +} diff --git a/imp/lib/Factory/Identity.php b/imp/lib/Factory/Identity.php new file mode 100644 index 000000000..41b69c426 --- /dev/null +++ b/imp/lib/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_Factory_Identity +{ + /** + * Return the IMP identity instance. + * + * @return IMP_Prefs_Identity The singleton instance. + */ + public function create(Horde_Injector $injector) + { + return $injector->getInstance('Horde_Core_Factory_Identity')->create(null, 'imp'); + } + +} diff --git a/imp/lib/Factory/Imap.php b/imp/lib/Factory/Imap.php new file mode 100644 index 000000000..9a21b8afa --- /dev/null +++ b/imp/lib/Factory/Imap.php @@ -0,0 +1,90 @@ + + * @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 IMP_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_Factory_Imap +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * The list of instances to save. + * + * @var array + */ + private $_save = array(); + + /** + * Return the IMP_Imap:: instance. + * + * @param string $id The server ID. + * @param boolean $save Save the instance in the session? + * + * @return IMP_Imap The singleton instance. + * @throws IMP_Exception + */ + public function create($id = null, $save = false) + { + global $session; + + if (is_null($id) && + !($id = $session->get('imp', 'server_key'))) { + $id = 'default'; + } + + if (!isset($this->_instances[$id])) { + if (!($ob = $session->get('imp', 'imap_ob/' . $id))) { + $ob = new IMP_Imap(); + } + + $this->_instances[$id] = $ob; + } + + if ($save && !$session->exists('imp', 'imap_ob/' . $id)) { + if (empty($this->_save)) { + register_shutdown_function(array($this, 'shutdown')); + } + $this->_save[] = $id; + } + + return $this->_instances[$id]; + } + + /** + * Saves IMP_Imap instances to the session. + */ + public function shutdown() + { + foreach (array_unique($this->_save) as $id) { + $GLOBALS['session']->set('imp', 'imap_ob/' . $id, $this->_instances[$id]); + } + } + +} diff --git a/imp/lib/Factory/Imaptree.php b/imp/lib/Factory/Imaptree.php new file mode 100644 index 000000000..73082cbf1 --- /dev/null +++ b/imp/lib/Factory/Imaptree.php @@ -0,0 +1,91 @@ + + * @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_Factory_Imaptree +{ + /** + * Return the IMP_Imap_Tree object. + * + * @return IMP_Imap_Tree The singleton instance. + */ + public function create(Horde_Injector $injector) + { + global $session; + + $instance = null; + + /* If an IMP_Imap_Tree object is currently stored in the cache, + * re-create that object. Else, create a new instance. */ + if ($session->exists('imp', 'treeob')) { + /* 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) { + $instance = $session->retrieve('imp_imaptree'); + } else { + try { + $instance = @unserialize($cache->get($session->get('imp', 'treeob'), 86400)); + } catch (Exception $e) { + Horde::logMessage('Could not unserialize stored IMP_Imap_Tree object.', 'DEBUG'); + } + } + } else { + $session->set('imp', 'treeob', strval(new Horde_Support_Randomid())); + } + + 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) + { + global $session; + + /* 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) { + $session->store($instance, true, 'imp_imaptree'); + } else { + $cache->set($GLOBALS['session']->get('imp', 'treeob'), serialize($instance), 86400); + } + } + } + +} diff --git a/imp/lib/Factory/Mail.php b/imp/lib/Factory/Mail.php new file mode 100644 index 000000000..ebe350d6a --- /dev/null +++ b/imp/lib/Factory/Mail.php @@ -0,0 +1,68 @@ + + * @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_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. */ + $params = array_merge($params, $GLOBALS['session']->get('imp', 'smtp', Horde_Session::TYPE_ARRAY)); + + /* 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_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/Factory/MailboxList.php b/imp/lib/Factory/MailboxList.php new file mode 100644 index 000000000..14cc786ee --- /dev/null +++ b/imp/lib/Factory/MailboxList.php @@ -0,0 +1,119 @@ + + * @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 IMP_Mailbox_List:: 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_Factory_MailboxList +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + register_shutdown_function(array($this, 'shutdown')); + } + + /** + * Return the mailbox list instance. + * For IMP/MIMP, returns an IMP_Mailbox_List_Track object. + * For DIMP/Mobile, returns an IMP_Mailbox_List object. + * + * @param string $mailbox The mailbox name. + * @param IMP_Indices $indices An indices object. Only used for 'imp' and + * 'mimp' views. + * + * @return IMP_Mailbox_List The singleton instance. + * @throws IMP_Exception + */ + public function create($mailbox, $indices = null) + { + $mode = IMP::getViewMode(); + + if (!isset($this->_instances[$mailbox])) { + switch ($mode) { + case 'dimp': + case 'mobile': + $ob = new IMP_Mailbox_List($mailbox); + break; + + case 'imp': + case 'mimp': + try { + $ob = $GLOBALS['session']->get('imp', 'imp_mailbox/' . $mailbox); + } catch (Exception $e) { + $ob = null; + } + + if (is_null($ob)) { + $ob = new IMP_Mailbox_List_Track($mailbox); + } + break; + } + + $this->_instances[$mailbox] = $ob; + } + + switch ($mode) { + case 'imp': + case 'mimp': + $this->_instances[$mailbox]->setIndex($indices); + $this->_instance[$mailbox]->checkcache = is_null($indices); + break; + } + + return $this->_instances[$mailbox]; + } + + /** + * Tasks to perform on shutdown. + */ + public function shutdown() + { + switch (IMP::getViewMode()) { + case 'imp': + case 'mimp': + /* Cache mailbox information if viewing in standard (IMP) message + * mode. Needed to keep navigation consistent when moving through + * the message list, and to ensure messages aren't marked as + * missing in search mailboxes (e.g. if search is dependent on + * unseen flag). */ + foreach ($this->_instances as $key => $val) { + if ($val->changed) { + $GLOBALS['session']->set('imp', 'imp_mailbox/' . $key, $val); + } + } + } + } + +} diff --git a/imp/lib/Factory/MimeViewer.php b/imp/lib/Factory/MimeViewer.php new file mode 100644 index 000000000..7998c0101 --- /dev/null +++ b/imp/lib/Factory/MimeViewer.php @@ -0,0 +1,96 @@ + + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + */ + +/** + * A Horde_Injector:: based Horde_Mime_Viewer factory for IMP drivers. + * + * 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_Factory_MimeViewer +{ + /** + * 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; + } + + /** + * Attempts to return a concrete Horde_Mime_Viewer object based on the + * MIME type. + * + * @param Horde_Mime_Part $mime An object with the data to be rendered. + * @param IMP_Contents $contents The IMP_Contents object associated with + * $mime. + * @param string $type The MIME type to use for loading. + * + * @return Horde_Mime_Viewer_Base The newly created instance. + * @throws Horde_Mime_Viewer_Exception + */ + public function create(Horde_Mime_Part $mime, + IMP_Contents $contents = null, $type = null) + { + list($driver, $params) = $this->_injector->getInstance('Horde_Core_Factory_MimeViewer')->getViewerConfig($type ? $type : $mime->getType(), 'imp'); + + switch ($driver) { + case 'Report': + case 'Security': + $params['viewer_callback'] = array($this, 'createCallback'); + break; + } + + $params['imp_contents'] = $contents; + + return Horde_Mime_Viewer::factory($driver, $mime, $params); + } + + /** + * Callback used to return a MIME Viewer object from within certain + * Viewer drivers. + * + * @param Horde_Mime_Viewer_Base $viewer The MIME Viewer driver + * requesting the new object. + * @param Horde_Mime_Part $mime An object with the data to be + * rendered. + * @param string $type The MIME type to use for + * rendering. + * + * @return Horde_Mime_Viewer_Base The newly created instance. + * @throws Horde_Mime_Viewer_Exception + */ + public function createCallback(Horde_Mime_Viewer_Base $viewer, + Horde_Mime_Part $mime, $type) + { + return $this->create($mime, $viewer->getConfigParam('imp_contents'), $type); + } + +} diff --git a/imp/lib/Factory/Pgp.php b/imp/lib/Factory/Pgp.php new file mode 100644 index 000000000..205ffb72b --- /dev/null +++ b/imp/lib/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_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/Factory/Quota.php b/imp/lib/Factory/Quota.php new file mode 100644 index 000000000..a526eecf8 --- /dev/null +++ b/imp/lib/Factory/Quota.php @@ -0,0 +1,75 @@ + + * @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_Factory_Quota +{ + /** + * Return the IMP_Quota instance. + * + * @return IMP_Quota The singleton instance. + * @throws IMP_Exception + */ + public function create(Horde_Injector $injector) + { + $qparams = $GLOBALS['session']->get('imp', 'imap_quota'); + + if (!isset($qparams['driver'])) { + throw new IMP_Exception('Quota config missing driver parameter.'); + } + $driver = $qparams['driver']; + $params = isset($qparams['params']) + ? $qparams['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']); + } + + $imap_ob = $injector->getInstance('IMP_Factory_Imap')->create(); + + switch (Horde_String::lower($driver)) { + case 'imap': + $params['imap_ob'] = $imap_ob; + $params['mbox'] = $injector->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) + ? 'INBOX' + : IMP::$mailbox; + break; + + case 'sql': + $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params); + break; + } + + $params['username'] = $imap_ob->getParam('username'); + + return IMP_Quota::factory($driver, $params); + } + +} diff --git a/imp/lib/Factory/Search.php b/imp/lib/Factory/Search.php new file mode 100644 index 000000000..12677a0f9 --- /dev/null +++ b/imp/lib/Factory/Search.php @@ -0,0 +1,66 @@ + + * @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_Factory_Search +{ + /** + * Return the IMP_Search instance. + * + * @return IMP_Search The singleton instance. + */ + public function create(Horde_Injector $injector) + { + try { + $instance = $GLOBALS['session']->get('imp', 'search'); + } catch (Exception $e) { + Horde::logMessage('Could not unserialize stored IMP_Search object.', 'DEBUG'); + $instance = null; + } + + 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. + * + * @param IMP_Search $instance Search object. + */ + public function shutdown($instance) + { + /* Only need to store the object if the object has changed. */ + if ($instance->changed) { + $GLOBALS['session']->set('imp', 'search', $instance); + } + } + +} diff --git a/imp/lib/Factory/Sentmail.php b/imp/lib/Factory/Sentmail.php new file mode 100644 index 000000000..e2333f2b1 --- /dev/null +++ b/imp/lib/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_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/Factory/Smime.php b/imp/lib/Factory/Smime.php new file mode 100644 index 000000000..1e3c75268 --- /dev/null +++ b/imp/lib/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_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'); + } + +} diff --git a/imp/lib/Filter.php b/imp/lib/Filter.php index b9affcef9..ca3fac58d 100644 --- a/imp/lib/Filter.php +++ b/imp/lib/Filter.php @@ -111,7 +111,7 @@ class IMP_Filter } $addr = array(); - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); foreach (array_keys($indices) as $mbox) { $imp_imap->checkUidvalidity($mbox); @@ -119,7 +119,7 @@ class IMP_Filter /* Get the list of from addresses. */ foreach ($indices as $mbox => $idx) { - $contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); + $contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); $hdr = $contents->getHeaderOb(); $addr[] = Horde_Mime_Address::bareAddress($hdr->getValue('from')); } diff --git a/imp/lib/Flag/User.php b/imp/lib/Flag/User.php index b2b6e2324..a00e2560d 100644 --- a/imp/lib/Flag/User.php +++ b/imp/lib/Flag/User.php @@ -55,7 +55,7 @@ class IMP_Flag_User extends IMP_Flag_Imap case 'imapflag': /* IMAP keywords must conform to RFC 3501 [9] (flag-keyword). * Convert whitespace to underscore. */ - $this->_imapflag = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getUtils()->stripNonAtomChars(Horde_String::convertCharset(strtr($value, ' ', '_'), 'UTF-8', 'UTF7-IMAP')); + $this->_imapflag = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getUtils()->stripNonAtomChars(Horde_String::convertCharset(strtr($value, ' ', '_'), 'UTF-8', 'UTF7-IMAP')); break; case 'label': diff --git a/imp/lib/Flags.php b/imp/lib/Flags.php index 371ccf0a6..6f2d4681b 100644 --- a/imp/lib/Flags.php +++ b/imp/lib/Flags.php @@ -117,7 +117,7 @@ class IMP_Flags implements ArrayAccess, Serializable try { /* Make sure we are in R/W mailbox mode (SELECT). No flags are * allowed in EXAMINE mode. */ - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $imp_imap->openMailbox($opts['mailbox'], Horde_Imap_Client::OPEN_READWRITE); $status = $imp_imap->status($opts['mailbox'], Horde_Imap_Client::STATUS_PERMFLAGS); } catch (Horde_Imap_Client_Exception $e) { diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index 3d6eedaaf..6f95a6e4c 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -55,7 +55,7 @@ class IMP_Folder } try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->deleteMailbox($folder); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->deleteMailbox($folder); $notification->push(sprintf(_("The folder \"%s\" was successfully deleted."), IMP::displayFolder($folder)), 'horde.success'); $deleted[] = $folder; } catch (Horde_Imap_Client_Exception $e) { @@ -143,7 +143,7 @@ class IMP_Folder /* Attempt to create the mailbox. */ try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->createMailbox($folder, array('special_use' => $special_use)); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->createMailbox($folder, array('special_use' => $special_use)); } catch (Horde_Imap_Client_Exception $e) { $notification->push(sprintf(_("The folder \"%s\" was not created. This is what the server said"), IMP::displayFolder($folder)) . ': ' . $e->getMessage(), 'horde.error'); return false; @@ -177,7 +177,7 @@ class IMP_Folder } try { - $ret = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->listMailboxes($folder, array('flat' => true)); + $ret = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->listMailboxes($folder, array('flat' => true)); return !empty($ret); } catch (Horde_Imap_Client_Exception $e) { return false; @@ -214,7 +214,7 @@ class IMP_Folder $all_folders = $this->getAllSubfolders($old); try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->renameMailbox($old, $new); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->renameMailbox($old, $new); } catch (Horde_Imap_Client_Exception $e) { $GLOBALS['notification']->push(sprintf(_("Renaming \"%s\" to \"%s\" failed. This is what the server said"), IMP::displayFolder($old), IMP::displayFolder($new)) . ': ' . $e->getMessage(), 'horde.error'); return false; @@ -258,7 +258,7 @@ class IMP_Folder foreach (array_filter($folders) as $folder) { try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->subscribeMailbox($folder, true); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->subscribeMailbox($folder, true); $notification->push(sprintf(_("You were successfully subscribed to \"%s\""), IMP::displayFolder($folder)), 'horde.success'); $subscribed[] = $folder; } catch (Horde_Imap_Client_Exception $e) { @@ -298,7 +298,7 @@ class IMP_Folder $notification->push(sprintf(_("You cannot unsubscribe from \"%s\"."), IMP::displayFolder($folder)), 'horde.error'); } else { try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->subscribeMailbox($folder, false); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->subscribeMailbox($folder, false); $notification->push(sprintf(_("You were successfully unsubscribed from \"%s\""), IMP::displayFolder($folder)), 'horde.success'); $unsubscribed[] = $folder; } catch (Horde_Imap_Client_Exception $e) { @@ -339,7 +339,7 @@ class IMP_Folder foreach ($folder_list as $folder) { try { - $status = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->status($folder, Horde_Imap_Client::STATUS_MESSAGES); + $status = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->status($folder, Horde_Imap_Client::STATUS_MESSAGES); } catch (Horde_Imap_Client_Exception $e) { continue; } @@ -347,7 +347,7 @@ class IMP_Folder /* Download one message at a time to save on memory * overhead. */ try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($folder, array( + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($folder, array( Horde_Imap_Client::FETCH_FULLMSG => array('peek' => true, 'stream' => true), Horde_Imap_Client::FETCH_ENVELOPE => true, Horde_Imap_Client::FETCH_DATE => true, @@ -392,7 +392,7 @@ class IMP_Folder { $message = ''; $msgcount = 0; - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $fd = fopen($mbox, 'r'); while (!feof($fd)) { diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 53d8c33a4..38ee2301d 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -348,7 +348,7 @@ class IMP return $cache[$folder]; } - $ns_info = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getNamespace($folder); + $ns_info = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getNamespace($folder); $delimiter = is_null($ns_info) ? '' : $ns_info['delimiter']; /* Substitute any translated prefix text. */ @@ -418,7 +418,7 @@ class IMP { $t = $GLOBALS['injector']->createInstance('Horde_Template'); $t->set('forminput', Horde_Util::formInput()); - $t->set('use_folders', $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders(), true); + $t->set('use_folders', $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->allowFolders(), true); if ($t->get('use_folders')) { Horde::addScriptFile('imp.js', 'imp'); $menu_view = $GLOBALS['prefs']->getValue('menu_view'); @@ -547,7 +547,7 @@ class IMP */ static public function folderPref($folder, $append) { - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $def_ns = $imp_imap->defaultNamespace(); $empty_ns = $imp_imap->getNamespace(''); diff --git a/imp/lib/Imap/Acl.php b/imp/lib/Imap/Acl.php index d565dadd9..a6a4425c4 100644 --- a/imp/lib/Imap/Acl.php +++ b/imp/lib/Imap/Acl.php @@ -45,7 +45,7 @@ class IMP_Imap_Acl throw new IMP_Exception(_("ACLs not configured for this server.")); } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); if (!$imp_imap->queryCapability('ACL')) { throw new IMP_Exception(_("IMAP server does not support ACLs.")); } @@ -129,7 +129,7 @@ class IMP_Imap_Acl public function getACL($mbox) { try { - return $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getACL($mbox); + return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getACL($mbox); } catch (Horde_Imap_Client_Exception $e) { throw new IMP_Exception(_("Could not retrieve ACL")); } @@ -147,7 +147,7 @@ class IMP_Imap_Acl public function editACL($mbox, $user, $acl) { try { - $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->setACL($mbox, $user, array('remove' => empty($acl), 'rights' => implode('', $acl))); + $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->setACL($mbox, $user, array('remove' => empty($acl), 'rights' => implode('', $acl))); } catch (Horde_Imap_Client_Exception $e) { throw new IMP_Exception(sprintf(_("Couldn't give user \"%s\" the following rights for the folder \"%s\": %s"), $user, $mbox, implode('', $acl))); } @@ -164,7 +164,7 @@ class IMP_Imap_Acl public function canEdit($mbox, $user) { try { - $rights = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->listACLRights($mbox, $user); + $rights = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->listACLRights($mbox, $user); $rights = array_merge($rights['required'], $rights['optional']); foreach ($rights as $val) { if (strpos($val, 'a') !== false) { diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index fdd795999..ec19652df 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -187,7 +187,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator, Serializable unset($this->_cache['fulllist'], $this->_cache['subscribed']); /* Do IMAP specific initialization. */ - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if ($session->get('imp', 'protocol') == 'imap') { $ns = $imp_imap->getNamespaceList(); $ptr = reset($ns); @@ -264,7 +264,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator, Serializable } try { - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $result = $imp_imap->listMailboxes($searches, $showunsub ? Horde_Imap_Client::MBOX_ALL : Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, array('attributes' => true, 'delimiter' => true, 'sort' => true)); /* INBOX must always appear. */ @@ -470,7 +470,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator, Serializable if (!empty($id)) { try { - $this->_insert($GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->listMailboxes($id, Horde_Imap_Client::MBOX_ALL, array('attributes' => true, 'delimiter' => true, 'sort' => true))); + $this->_insert($GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->listMailboxes($id, Horde_Imap_Client::MBOX_ALL, array('attributes' => true, 'delimiter' => true, 'sort' => true))); } catch (Horde_Imap_Client_Exception $e) {} } } @@ -1262,7 +1262,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator, Serializable { if (!in_array($mailbox, array(self::OTHER_KEY, self::SHARED_KEY, self::VFOLDER_KEY)) && (strpos($mailbox, self::VFOLDER_KEY . $this->_delimiter) !== 0)) { - return $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getNamespace($mailbox); + return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getNamespace($mailbox); } return null; } @@ -1324,7 +1324,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator, Serializable $this->changed = true; } - if (!$GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { + if (!$GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { return; } @@ -1429,7 +1429,7 @@ class IMP_Imap_Tree implements ArrayAccess, Iterator, Serializable public function createMailboxName($parent, $new) { $ns_info = empty($parent) - ? $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->defaultNamespace() + ? $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->defaultNamespace() : $this->_getNamespace($parent); if (is_null($ns_info)) { diff --git a/imp/lib/Imap/Tree/Element.php b/imp/lib/Imap/Tree/Element.php index 3c6485c97..7a1874b95 100644 --- a/imp/lib/Imap/Tree/Element.php +++ b/imp/lib/Imap/Tree/Element.php @@ -157,7 +157,7 @@ class IMP_Imap_Tree_Element $info->unseen = 0; try { - if ($msgs_info = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->status($this->value, Horde_Imap_Client::STATUS_RECENT | Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES)) { + if ($msgs_info = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->status($this->value, Horde_Imap_Client::STATUS_RECENT | Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES)) { if (!empty($msgs_info['recent'])) { $info->recent = intval($msgs_info['recent']); } diff --git a/imp/lib/Indices.php b/imp/lib/Indices.php index f24a12f5d..44903d82b 100644 --- a/imp/lib/Indices.php +++ b/imp/lib/Indices.php @@ -81,7 +81,7 @@ class IMP_Indices implements Countable, Iterator } } } elseif (is_string($data)) { - $indices = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getUtils()->fromSequenceString($data); + $indices = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getUtils()->fromSequenceString($data); } elseif ($data instanceof IMP_Compose) { $indices = array( $data->getMetadata('mailbox') => array($data->getMetadata('uid')) @@ -184,7 +184,7 @@ class IMP_Indices implements Countable, Iterator */ public function __toString() { - return $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getUtils()->toSequenceString($this->_indices, array('mailbox' => true)); + return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getUtils()->toSequenceString($this->_indices, array('mailbox' => true)); } /* Iterator methods. */ diff --git a/imp/lib/Injector/Factory/AuthImap.php b/imp/lib/Injector/Factory/AuthImap.php deleted file mode 100644 index 02331606f..000000000 --- a/imp/lib/Injector/Factory/AuthImap.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @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.'); - } - - $aparams = $GLOBALS['session']->get('imp', 'imap_admin', Horde_Session::TYPE_ARRAY); - - $params = array_merge( - $params, - (isset($aparams['params']) ? $aparams['params'] : array()), - 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/Compose.php b/imp/lib/Injector/Factory/Compose.php deleted file mode 100644 index 3b19517a1..000000000 --- a/imp/lib/Injector/Factory/Compose.php +++ /dev/null @@ -1,112 +0,0 @@ - - * @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 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. - * - * @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_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; - - register_shutdown_function(array($this, 'shutdown')); - } - - /** - * Return the IMP_Compose:: instance. - * - * @param string $cacheid The cache ID string. - * - * @return IMP_Compose The singleton compose instance. - * @throws IMP_Exception - */ - public function create($cacheid = null) - { - if (empty($cacheid)) { - $cacheid = strval(new Horde_Support_Randomid()); - } elseif (!isset($this->_instances[$cacheid])) { - $this->_instances[$cacheid] = $GLOBALS['session']->retrieve($cacheid); - } - - if (empty($this->_instances[$cacheid])) { - $this->_instances[$cacheid] = new IMP_Compose($cacheid); - } - - return $this->_instances[$cacheid]; - } - - /** - * Tasks to perform on shutdown. - */ - public function shutdown() - { - global $session; - - $cache = $session->get('imp', 'compose_cache', Horde_Session::TYPE_ARRAY); - $changed = false; - - foreach ($this->_instances as $key => $val) { - switch ($val->changed) { - case 'changed': - $val->changed = ''; - $session->store($val, false, $key); - $cache[$key] = 1; - $changed = true; - break; - - case 'deleted': - unset($cache[$key]); - $session->purge($key); - $changed = true; - break; - } - - } - - if ($changed) { - $session->set('imp', 'compose_cache', $cache); - } - } - -} diff --git a/imp/lib/Injector/Factory/Contents.php b/imp/lib/Injector/Factory/Contents.php deleted file mode 100644 index 5447df689..000000000 --- a/imp/lib/Injector/Factory/Contents.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @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 IMP_Contents:: 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_Contents -{ - /** - * Instances. - * - * @var array - */ - private $_instances = array(); - - /** - * Return the IMP_Contents:: instance. - * - * @param IMP_Indices $indices An indices object. - * - * @return IMP_Contents The singleton contents instance. - * @throws IMP_Exception - */ - public function create($indices) - { - $key = strval($indices); - - if (!isset($this->_instances[$key])) { - $this->_instances[$key] = new IMP_Contents($indices); - } - - return $this->_instances[$key]; - } - -} diff --git a/imp/lib/Injector/Factory/Flags.php b/imp/lib/Injector/Factory/Flags.php deleted file mode 100644 index f4f255ebf..000000000 --- a/imp/lib/Injector/Factory/Flags.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @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_Flags 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_Flags -{ - /** - * Return the IMP_Flags instance. - * - * @return IMP_Flags The singleton instance. - */ - public function create(Horde_Injector $injector) - { - try { - $instance = $GLOBALS['session']->get('imp', 'flags'); - } catch (Exception $e) { - Horde::logMessage('Could not unserialize stored IMP_Flags object.', 'DEBUG'); - $instance = null; - } - - if (is_null($instance)) { - $instance = new IMP_Flags(); - } - - register_shutdown_function(array($this, 'shutdown'), $instance); - - return $instance; - } - - /** - * Store serialized version of object in the current session. - * - * @param IMP_Flags $instance Flags object. - */ - public function shutdown($instance) - { - /* Only need to store the object if the object has changed. */ - if ($instance->changed) { - $GLOBALS['session']->set('imp', 'flags', $instance); - } - } - -} diff --git a/imp/lib/Injector/Factory/Identity.php b/imp/lib/Injector/Factory/Identity.php deleted file mode 100644 index 16fd85fac..000000000 --- a/imp/lib/Injector/Factory/Identity.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @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_Core_Factory_Identity')->create(null, 'imp'); - } - -} diff --git a/imp/lib/Injector/Factory/Imap.php b/imp/lib/Injector/Factory/Imap.php deleted file mode 100644 index c5389d0e2..000000000 --- a/imp/lib/Injector/Factory/Imap.php +++ /dev/null @@ -1,90 +0,0 @@ - - * @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 IMP_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_Imap -{ - /** - * Instances. - * - * @var array - */ - private $_instances = array(); - - /** - * The list of instances to save. - * - * @var array - */ - private $_save = array(); - - /** - * Return the IMP_Imap:: instance. - * - * @param string $id The server ID. - * @param boolean $save Save the instance in the session? - * - * @return IMP_Imap The singleton instance. - * @throws IMP_Exception - */ - public function create($id = null, $save = false) - { - global $session; - - if (is_null($id) && - !($id = $session->get('imp', 'server_key'))) { - $id = 'default'; - } - - if (!isset($this->_instances[$id])) { - if (!($ob = $session->get('imp', 'imap_ob/' . $id))) { - $ob = new IMP_Imap(); - } - - $this->_instances[$id] = $ob; - } - - if ($save && !$session->exists('imp', 'imap_ob/' . $id)) { - if (empty($this->_save)) { - register_shutdown_function(array($this, 'shutdown')); - } - $this->_save[] = $id; - } - - return $this->_instances[$id]; - } - - /** - * Saves IMP_Imap instances to the session. - */ - public function shutdown() - { - foreach (array_unique($this->_save) as $id) { - $GLOBALS['session']->set('imp', 'imap_ob/' . $id, $this->_instances[$id]); - } - } - -} diff --git a/imp/lib/Injector/Factory/Imaptree.php b/imp/lib/Injector/Factory/Imaptree.php deleted file mode 100644 index af544786c..000000000 --- a/imp/lib/Injector/Factory/Imaptree.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @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) - { - global $session; - - $instance = null; - - /* If an IMP_Imap_Tree object is currently stored in the cache, - * re-create that object. Else, create a new instance. */ - if ($session->exists('imp', 'treeob')) { - /* 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) { - $instance = $session->retrieve('imp_imaptree'); - } else { - try { - $instance = @unserialize($cache->get($session->get('imp', 'treeob'), 86400)); - } catch (Exception $e) { - Horde::logMessage('Could not unserialize stored IMP_Imap_Tree object.', 'DEBUG'); - } - } - } else { - $session->set('imp', 'treeob', strval(new Horde_Support_Randomid())); - } - - 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) - { - global $session; - - /* 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) { - $session->store($instance, true, 'imp_imaptree'); - } else { - $cache->set($GLOBALS['session']->get('imp', 'treeob'), serialize($instance), 86400); - } - } - } - -} diff --git a/imp/lib/Injector/Factory/Mail.php b/imp/lib/Injector/Factory/Mail.php deleted file mode 100644 index 39ab5a52b..000000000 --- a/imp/lib/Injector/Factory/Mail.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @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. */ - $params = array_merge($params, $GLOBALS['session']->get('imp', 'smtp', Horde_Session::TYPE_ARRAY)); - - /* 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/MailboxList.php b/imp/lib/Injector/Factory/MailboxList.php deleted file mode 100644 index 406db4666..000000000 --- a/imp/lib/Injector/Factory/MailboxList.php +++ /dev/null @@ -1,119 +0,0 @@ - - * @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 IMP_Mailbox_List:: 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_MailboxList -{ - /** - * Instances. - * - * @var array - */ - private $_instances = array(); - - /** - * Constructor. - * - * @param Horde_Injector $injector The injector to use. - */ - public function __construct(Horde_Injector $injector) - { - register_shutdown_function(array($this, 'shutdown')); - } - - /** - * Return the mailbox list instance. - * For IMP/MIMP, returns an IMP_Mailbox_List_Track object. - * For DIMP/Mobile, returns an IMP_Mailbox_List object. - * - * @param string $mailbox The mailbox name. - * @param IMP_Indices $indices An indices object. Only used for 'imp' and - * 'mimp' views. - * - * @return IMP_Mailbox_List The singleton instance. - * @throws IMP_Exception - */ - public function create($mailbox, $indices = null) - { - $mode = IMP::getViewMode(); - - if (!isset($this->_instances[$mailbox])) { - switch ($mode) { - case 'dimp': - case 'mobile': - $ob = new IMP_Mailbox_List($mailbox); - break; - - case 'imp': - case 'mimp': - try { - $ob = $GLOBALS['session']->get('imp', 'imp_mailbox/' . $mailbox); - } catch (Exception $e) { - $ob = null; - } - - if (is_null($ob)) { - $ob = new IMP_Mailbox_List_Track($mailbox); - } - break; - } - - $this->_instances[$mailbox] = $ob; - } - - switch ($mode) { - case 'imp': - case 'mimp': - $this->_instances[$mailbox]->setIndex($indices); - $this->_instance[$mailbox]->checkcache = is_null($indices); - break; - } - - return $this->_instances[$mailbox]; - } - - /** - * Tasks to perform on shutdown. - */ - public function shutdown() - { - switch (IMP::getViewMode()) { - case 'imp': - case 'mimp': - /* Cache mailbox information if viewing in standard (IMP) message - * mode. Needed to keep navigation consistent when moving through - * the message list, and to ensure messages aren't marked as - * missing in search mailboxes (e.g. if search is dependent on - * unseen flag). */ - foreach ($this->_instances as $key => $val) { - if ($val->changed) { - $GLOBALS['session']->set('imp', 'imp_mailbox/' . $key, $val); - } - } - } - } - -} diff --git a/imp/lib/Injector/Factory/MimeViewer.php b/imp/lib/Injector/Factory/MimeViewer.php deleted file mode 100644 index 3be02276f..000000000 --- a/imp/lib/Injector/Factory/MimeViewer.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @link http://pear.horde.org/index.php?package=IMP - */ - -/** - * A Horde_Injector:: based Horde_Mime_Viewer factory for IMP drivers. - * - * 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_MimeViewer -{ - /** - * 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; - } - - /** - * Attempts to return a concrete Horde_Mime_Viewer object based on the - * MIME type. - * - * @param Horde_Mime_Part $mime An object with the data to be rendered. - * @param IMP_Contents $contents The IMP_Contents object associated with - * $mime. - * @param string $type The MIME type to use for loading. - * - * @return Horde_Mime_Viewer_Base The newly created instance. - * @throws Horde_Mime_Viewer_Exception - */ - public function create(Horde_Mime_Part $mime, - IMP_Contents $contents = null, $type = null) - { - list($driver, $params) = $this->_injector->getInstance('Horde_Core_Factory_MimeViewer')->getViewerConfig($type ? $type : $mime->getType(), 'imp'); - - switch ($driver) { - case 'Report': - case 'Security': - $params['viewer_callback'] = array($this, 'createCallback'); - break; - } - - $params['imp_contents'] = $contents; - - return Horde_Mime_Viewer::factory($driver, $mime, $params); - } - - /** - * Callback used to return a MIME Viewer object from within certain - * Viewer drivers. - * - * @param Horde_Mime_Viewer_Base $viewer The MIME Viewer driver - * requesting the new object. - * @param Horde_Mime_Part $mime An object with the data to be - * rendered. - * @param string $type The MIME type to use for - * rendering. - * - * @return Horde_Mime_Viewer_Base The newly created instance. - * @throws Horde_Mime_Viewer_Exception - */ - public function createCallback(Horde_Mime_Viewer_Base $viewer, - Horde_Mime_Part $mime, $type) - { - return $this->create($mime, $viewer->getConfigParam('imp_contents'), $type); - } - -} diff --git a/imp/lib/Injector/Factory/Pgp.php b/imp/lib/Injector/Factory/Pgp.php deleted file mode 100644 index 6a5f41c3d..000000000 --- a/imp/lib/Injector/Factory/Pgp.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @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 deleted file mode 100644 index f5f6c264f..000000000 --- a/imp/lib/Injector/Factory/Quota.php +++ /dev/null @@ -1,75 +0,0 @@ - - * @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. - * @throws IMP_Exception - */ - public function create(Horde_Injector $injector) - { - $qparams = $GLOBALS['session']->get('imp', 'imap_quota'); - - if (!isset($qparams['driver'])) { - throw new IMP_Exception('Quota config missing driver parameter.'); - } - $driver = $qparams['driver']; - $params = isset($qparams['params']) - ? $qparams['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']); - } - - $imap_ob = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); - - switch (Horde_String::lower($driver)) { - case 'imap': - $params['imap_ob'] = $imap_ob; - $params['mbox'] = $injector->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) - ? 'INBOX' - : IMP::$mailbox; - break; - - case 'sql': - $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params); - break; - } - - $params['username'] = $imap_ob->getParam('username'); - - return IMP_Quota::factory($driver, $params); - } - -} diff --git a/imp/lib/Injector/Factory/Search.php b/imp/lib/Injector/Factory/Search.php deleted file mode 100644 index 17bcaea8f..000000000 --- a/imp/lib/Injector/Factory/Search.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @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) - { - try { - $instance = $GLOBALS['session']->get('imp', 'search'); - } catch (Exception $e) { - Horde::logMessage('Could not unserialize stored IMP_Search object.', 'DEBUG'); - $instance = null; - } - - 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. - * - * @param IMP_Search $instance Search object. - */ - public function shutdown($instance) - { - /* Only need to store the object if the object has changed. */ - if ($instance->changed) { - $GLOBALS['session']->set('imp', 'search', $instance); - } - } - -} diff --git a/imp/lib/Injector/Factory/Sentmail.php b/imp/lib/Injector/Factory/Sentmail.php deleted file mode 100644 index a31505822..000000000 --- a/imp/lib/Injector/Factory/Sentmail.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @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 deleted file mode 100644 index bb49da5c0..000000000 --- a/imp/lib/Injector/Factory/Smime.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @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'); - } - -} diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php index 4c6920ede..9d8bbe71a 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php @@ -40,7 +40,7 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4Auth extends Horde_LoginTasks_Sys protected function _upgradeExpireImapCache() { try { - $ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->ob; + $ob = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->ob; if ($cache = $ob->getCache()) { $ob->login(); diff --git a/imp/lib/Mailbox/List.php b/imp/lib/Mailbox/List.php index bcfd92702..fb3447588 100644 --- a/imp/lib/Mailbox/List.php +++ b/imp/lib/Mailbox/List.php @@ -164,7 +164,7 @@ class IMP_Mailbox_List implements Countable, Serializable )); } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); if (empty($options['preview'])) { $cache = null; @@ -201,7 +201,7 @@ class IMP_Mailbox_List implements Countable, Serializable !in_array('\\seen', $v['flags'])))) { if (empty($preview_info[$k])) { try { - $imp_contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mbox, $k)); + $imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $k)); $prev = $imp_contents->generatePreview(); $preview_info[$k] = array('IMPpreview' => $prev['text'], 'IMPpreviewc' => $prev['cut']); if (!is_null($cache)) { @@ -352,7 +352,7 @@ class IMP_Mailbox_List implements Countable, Serializable } $criteria = new Horde_Imap_Client_Search_Query(); - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); if (IMP::hideDeletedMsgs($this->_mailbox)) { $criteria->flag('\\deleted', false); @@ -455,7 +455,7 @@ class IMP_Mailbox_List implements Countable, Serializable $ret['anymsg'] = true; if (!$ret['msgcount'] && !$this->_searchmbox) { try { - $status = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->status($this->_mailbox, Horde_Imap_Client::STATUS_MESSAGES); + $status = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->status($this->_mailbox, Horde_Imap_Client::STATUS_MESSAGES); $ret['anymsg'] = (bool)$status['messages']; } catch (Horde_Imap_Client_Exception $e) { $ret['anymsg'] = false; @@ -496,7 +496,7 @@ class IMP_Mailbox_List implements Countable, Serializable * information is returned via a SELECT/EXAMINE call. */ if ($sortpref['by'] == Horde_Imap_Client::SORT_SEQUENCE) { try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN); + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN); if (!is_null($res['firstunseen'])) { return $res['firstunseen']; } @@ -528,7 +528,7 @@ class IMP_Mailbox_List implements Countable, Serializable { if (is_null($this->_threadob)) { try { - $this->_threadob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->thread($this->_mailbox, array('criteria' => $GLOBALS['session']->get('imp', 'imap_thread'))); + $this->_threadob = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->thread($this->_mailbox, array('criteria' => $GLOBALS['session']->get('imp', 'imap_thread'))); } catch (Horde_Imap_Client_Exception $e) { $GLOBALS['notification']->push($e); return new Horde_Imap_Client_Thread(array(), 'uid'); @@ -665,7 +665,7 @@ class IMP_Mailbox_List implements Countable, Serializable if (!$this->_searchmbox) { $sortpref = IMP::getSort($this->_mailbox, true); try { - return $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->getCacheId($this->_mailbox, array($sortpref['by'], $sortpref['dir'])); + return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getCacheId($this->_mailbox, array($sortpref['by'], $sortpref['dir'])); } catch (Horde_Imap_Client_Exception $e) {} } diff --git a/imp/lib/Message.php b/imp/lib/Message.php index 0f359b3cb..980968728 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -100,7 +100,7 @@ class IMP_Message break; } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); foreach ($indices->indices() as $mbox => $msgIndices) { $error = null; @@ -202,7 +202,7 @@ class IMP_Message } } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); foreach ($indices->indices() as $mbox => $msgIndices) { $error = null; @@ -330,7 +330,7 @@ class IMP_Message foreach ($indices as $folder => $index) { /* Fetch the message contents. */ - $imp_contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($folder, $index)); + $imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($folder, $index)); /* Fetch the message headers. */ $imp_headers = $imp_contents->getHeaderOb(); @@ -477,7 +477,7 @@ class IMP_Message return; } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); if ($imp_imap->isReadOnly($mbox)) { throw new IMP_Exception(_("Cannot strip the MIME part as the mailbox is read-only.")); @@ -485,7 +485,7 @@ class IMP_Message $uidvalidity = $imp_imap->checkUidvalidity($mbox); - $contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create($indices); + $contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($indices); $message = $contents->getMIMEMessage(); $boundary = trim($message->getContentTypeParameter('boundary'), '"'); @@ -615,7 +615,7 @@ class IMP_Message $action_array = $action ? array('add' => $flags) : array('remove' => $flags); - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); foreach ($indices->indices() as $mbox => $msgIndices) { $error = null; @@ -670,7 +670,7 @@ class IMP_Message $action_array = $action ? array('add' => $flags) : array('remove' => $flags); - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); foreach ($mboxes as $val) { try { @@ -710,7 +710,7 @@ class IMP_Message return $msg_list ? new IMP_Indices() : null; } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); $process_list = $update_list = array(); @@ -761,7 +761,7 @@ class IMP_Message { global $notification, $prefs; - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); $trash_folder = ($prefs->getValue('use_trash')) ? IMP::folderPref($prefs->getValue('trash_folder'), true) @@ -815,7 +815,7 @@ class IMP_Message public function sizeMailbox($mbox, $formatted = true) { try { - $res = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($mbox, array(Horde_Imap_Client::FETCH_SIZE => true), array('sequence' => true)); + $res = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($mbox, array(Horde_Imap_Client::FETCH_SIZE => true), array('sequence' => true)); $size = 0; reset($res); diff --git a/imp/lib/Mime/Viewer/Partial.php b/imp/lib/Mime/Viewer/Partial.php index 245f6170d..877626424 100644 --- a/imp/lib/Mime/Viewer/Partial.php +++ b/imp/lib/Mime/Viewer/Partial.php @@ -109,7 +109,7 @@ class IMP_Mime_Viewer_Partial extends Horde_Mime_Viewer_Base if ($val == $number) { $parts[$number] = $this->_mimepart->getContents(); } else { - $ic = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mbox, $val)); + $ic = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $val)); $parts[$ic->getMIMEMessage()->getContentTypeParameter('number')] = $ic->getBody(); } } diff --git a/imp/lib/Notification/Handler/Decorator/Imap.php b/imp/lib/Notification/Handler/Decorator/Imap.php index bc090ccb8..7d5765dca 100644 --- a/imp/lib/Notification/Handler/Decorator/Imap.php +++ b/imp/lib/Notification/Handler/Decorator/Imap.php @@ -25,7 +25,7 @@ extends Horde_Notification_Handler_Decorator_Base public function notify($options) { if (in_array('status', $options['listeners']) && - ($ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()) && + ($ob = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()) && $ob->ob) { /* Display IMAP alerts. */ foreach ($ob->alerts() as $alert) { diff --git a/imp/lib/Prefs/Identity.php b/imp/lib/Prefs/Identity.php index 40ff5e4df..c14053939 100644 --- a/imp/lib/Prefs/Identity.php +++ b/imp/lib/Prefs/Identity.php @@ -563,7 +563,7 @@ class Imp_Prefs_Identity extends Horde_Core_Prefs_Identity */ public function saveSentmail($ident = null) { - return $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders() + return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->allowFolders() ? $this->getValue('save_sent_mail', $ident) : false; } diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index cac8e9848..b48a56f5d 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -66,7 +66,7 @@ class IMP_Prefs_Ui $ui->suppressGroups[] = 'smime'; } - if (!$injector->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { + if (!$injector->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { $ui->suppressGroups[] = 'searches'; } @@ -129,7 +129,7 @@ class IMP_Prefs_Ui case 'alternative_display': $mock_part = new Horde_Mime_Part(); $mock_part->setType('text/html'); - $v = $injector->getInstance('IMP_Injector_Factory_MimeViewer')->create($mock_part); + $v = $injector->getInstance('IMP_Factory_MimeViewer')->create($mock_part); if (!$v->canRender('inline')) { $ui->suppress[] = 'alternative_display'; @@ -1020,7 +1020,7 @@ class IMP_Prefs_Ui $t = $injector->createInstance('Horde_Template'); $t->setOption('gettext', true); - if (!$injector->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { + if (!$injector->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { $t->set('nofolder', true); } else { $mailbox_selected = $prefs->getValue('initial_page'); @@ -1441,7 +1441,7 @@ class IMP_Prefs_Ui { global $injector, $prefs; - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!$imp_imap->allowFolders() || $prefs->isLocked('sent_mail_folder')) { @@ -1932,7 +1932,7 @@ class IMP_Prefs_Ui { global $injector, $prefs; - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!$imp_imap->allowFolders() || $prefs->isLocked($pref)) { @@ -1947,7 +1947,7 @@ class IMP_Prefs_Ui $folder = substr($folder, strlen(self::PREF_SPECIALUSE)); } elseif (!empty($new)) { $new = Horde_String::convertCharset($new, 'UTF-8', 'UTF7-IMAP'); - $folder = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->appendNamespace($new); + $folder = $injector->getInstance('IMP_Factory_Imap')->create()->appendNamespace($new); if (!$injector->getInstance('IMP_Folder')->create($folder, $prefs->getValue('subscribe'), array($type => true))) { $folder = null; } @@ -1968,7 +1968,7 @@ class IMP_Prefs_Ui protected function _getSpecialUse($use) { if (is_null($this->_cache)) { - $this->_cache = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array( + $this->_cache = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array( 'attributes' => true, 'special_use' => true, 'sort' => true diff --git a/imp/lib/Quota/Mdaemon.php b/imp/lib/Quota/Mdaemon.php index fb7721df2..c5fd11489 100644 --- a/imp/lib/Quota/Mdaemon.php +++ b/imp/lib/Quota/Mdaemon.php @@ -43,7 +43,7 @@ class IMP_Quota_Mdaemon extends IMP_Quota_Base */ public function getQuota() { - $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imap_ob = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $userDetails = $this->_getUserDetails( $this->_params['username'], $GLOBALS['session']->get('imp', 'maildomain') diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 70fcc1bcf..37f308280 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -154,7 +154,7 @@ class IMP_Search implements ArrayAccess, Iterator, Serializable */ public function imapSearch($mailbox, $query, $opts = array()) { - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); /* If doing a from/to search, use display sorting if possible. * Although there is a fallback to a PHP-based display sort, for diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index d00bcce84..be3b55417 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -43,7 +43,7 @@ class IMP_Spam return 0; } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $report_count = $result = 0; foreach ($indices->indices() as $mbox => $msgIndices) { @@ -57,7 +57,7 @@ class IMP_Spam /* Fetch the raw message contents (headers and complete * body). */ try { - $imp_contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); + $imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); } catch (IMP_Exception $e) { continue; } @@ -119,7 +119,7 @@ class IMP_Spam } if (!isset($imp_compose)) { - $imp_compose = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Compose')->create(); + $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create(); try { $from_line = $GLOBALS['injector']->getInstance('IMP_Identity')->getFromLine(); } catch (Horde_Exception $e) { diff --git a/imp/lib/Ui/Block.php b/imp/lib/Ui/Block.php index c52c155dc..80c547031 100644 --- a/imp/lib/Ui/Block.php +++ b/imp/lib/Ui/Block.php @@ -32,7 +32,7 @@ class IMP_Ui_Block $GLOBALS['injector']->getInstance('IMP_Filter')->filter('INBOX'); } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); /* Get list of mailboxes to poll. */ $poll = $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(true); diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index e0fc95738..fe03fb6e2 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -171,7 +171,7 @@ class IMP_Ui_Compose if (!is_null($indices)) { try { - $ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create($indices); + $ob = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($indices); } catch (Horde_Exception $e) {} } diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index dc06cc1e5..196b21c16 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -70,7 +70,7 @@ class IMP_Ui_Message */ public function MDNCheck($mailbox, $uid, $headers, $confirmed = false) { - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); $pref_val = $GLOBALS['prefs']->getValue('send_mdn'); if (!$pref_val || $imp_imap->isReadOnly($mailbox)) { diff --git a/imp/lib/Views/Compose.php b/imp/lib/Views/Compose.php index 342e11eb6..a8cf8060e 100644 --- a/imp/lib/Views/Compose.php +++ b/imp/lib/Views/Compose.php @@ -45,7 +45,7 @@ class IMP_Views_Compose $t->setOption('gettext', true); if (!empty($args['composeCache'])) { - $imp_compose = $injector->getInstance('IMP_Injector_Factory_Compose')->create($args['composeCache']); + $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($args['composeCache']); $t->set('composeCache', $args['composeCache']); } @@ -140,7 +140,7 @@ class IMP_Views_Compose $t->set('read_receipt_set', ($d_read != 'ask')); } - $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); $t->set('save_sent_mail', ($imp_imap->allowFolders() && !$prefs->isLocked('save_sent_mail'))); $t->set('priority', $prefs->getValue('set_priority')); if (!$prefs->isLocked('default_encrypt') && diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 71db09491..4622eaa59 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -106,7 +106,7 @@ class IMP_Views_ListMessages } /* Generate the sorted mailbox list now. */ - $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($mbox); + $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Factory_MailboxList')->create($mbox); $sorted_list = $imp_mailbox->getSortedList(); $msgcount = count($sorted_list['s']); @@ -173,7 +173,7 @@ class IMP_Views_ListMessages } } - $imp_imap = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create(); /* These entries may change during a session, so always need to * update them. */ diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php index 3a4d31bef..2465e5447 100644 --- a/imp/lib/Views/ShowMessage.php +++ b/imp/lib/Views/ShowMessage.php @@ -110,14 +110,14 @@ class IMP_Views_ShowMessage * view. */ $imp_contents = null; try { - $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($mailbox, array( + $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->fetch($mailbox, array( Horde_Imap_Client::FETCH_ENVELOPE => true, Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => false)) ), array('ids' => array($uid))); if (isset($fetch_ret[$uid]['headertext'])) { /* Parse MIME info and create the body of the message. */ - $imp_contents = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mailbox, $uid)); + $imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mailbox, $uid)); } } catch (Horde_Imap_Client_Exception $e) { } catch (IMP_Exception $e) {} diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index 24fb4fe41..fc2cb13eb 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -37,7 +37,7 @@ $t = $injector->createInstance('Horde_Template'); $t->setOption('gettext', true); /* Determine if mailbox is readonly. */ -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); $readonly = $imp_imap->isReadOnly(IMP::$mailbox); /* Get the base URL for this page. */ @@ -125,7 +125,7 @@ case 'rs': } /* Build the list of messages in the mailbox. */ -$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox); +$imp_mailbox = $injector->getInstance('IMP_Factory_MailboxList')->create(IMP::$mailbox); $pageOb = $imp_mailbox->buildMailboxPage($vars->p, $vars->s); /* Generate page title. */ diff --git a/imp/mailbox.php b/imp/mailbox.php index 3ae3c5193..d22c92730 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -65,7 +65,7 @@ if (!Horde_Util::nonInputVar('from_message_page')) { $do_filter = false; $imp_flags = $injector->getInstance('IMP_Flags'); -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); $indices = new IMP_Indices($vars->indices); /* Run through the action handlers */ @@ -235,7 +235,7 @@ if ($imp_imap->allowFolders()) { } /* Build the list of messages in the mailbox. */ -$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox); +$imp_mailbox = $injector->getInstance('IMP_Factory_MailboxList')->create(IMP::$mailbox); $pageOb = $imp_mailbox->buildMailboxPage($vars->page, $start); $show_preview = $prefs->getValue('preview_enabled'); diff --git a/imp/message-dimp.php b/imp/message-dimp.php index 618caf1af..bc2e9f3e4 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -23,7 +23,7 @@ if (!$vars->uid || !$vars->folder) { $imp_ui = new IMP_Ui_Message(); $js_onload = $js_vars = array(); -$readonly = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->isReadOnly($vars->folder); +$readonly = $injector->getInstance('IMP_Factory_Imap')->create()->isReadOnly($vars->folder); switch ($vars->actionID) { case 'strip_attachment': diff --git a/imp/message-mimp.php b/imp/message-mimp.php index bc76cf6f1..f2d737059 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -29,12 +29,12 @@ Horde_Registry::appInit('imp', array( $vars = Horde_Variables::getDefaultVariables(); /* Make sure we have a valid index. */ -$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid)); +$imp_mailbox = $injector->getInstance('IMP_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid)); if (!$imp_mailbox->isValidIndex()) { IMP::generateIMPUrl('mailbox-mimp.php', IMP::$mailbox)->add('a', 'm')->redirect(); } -$readonly = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->isReadOnly(IMP::$mailbox); +$readonly = $injector->getInstance('IMP_Factory_Imap')->create()->isReadOnly(IMP::$mailbox); $imp_ui_mimp = $injector->getInstance('IMP_Ui_Mimp'); $imp_hdr_ui = new IMP_Ui_Headers(); @@ -100,10 +100,10 @@ $uid = $index_ob['uid']; try { /* Need to fetch flags before HEADERTEXT, because SEEN flag might be set * before we can grab it. */ - $flags_ret = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($mailbox_name, array( + $flags_ret = $injector->getInstance('IMP_Factory_Imap')->create()->fetch($mailbox_name, array( Horde_Imap_Client::FETCH_FLAGS => true, ), array('ids' => array($uid))); - $fetch_ret = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($mailbox_name, array( + $fetch_ret = $injector->getInstance('IMP_Factory_Imap')->create()->fetch($mailbox_name, array( Horde_Imap_Client::FETCH_ENVELOPE => true, Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => $readonly)) ), array('ids' => array($uid))); @@ -118,7 +118,7 @@ $use_pop = ($session->get('imp', 'protocol') == 'pop'); /* Parse the message. */ try { - $imp_contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($imp_mailbox)); + $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imp_mailbox)); } catch (IMP_Exception $e) { IMP::generateIMPUrl('mailbox-mimp.php', $mailbox_name)->add('a', 'm')->redirect(); } diff --git a/imp/message.php b/imp/message.php index 1b1e0e785..07ff984ac 100644 --- a/imp/message.php +++ b/imp/message.php @@ -32,11 +32,11 @@ $registry->setTimeZone(); * select it on the IMAP server (saves some STATUS calls). Open R/W to clear * the RECENT flag. */ if (!($search_mbox = $injector->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox))) { - $injector->getInstance('IMP_Injector_Factory_Imap')->create()->openMailbox(IMP::$mailbox, Horde_Imap_Client::OPEN_READWRITE); + $injector->getInstance('IMP_Factory_Imap')->create()->openMailbox(IMP::$mailbox, Horde_Imap_Client::OPEN_READWRITE); } /* Make sure we have a valid index. */ -$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid)); +$imp_mailbox = $injector->getInstance('IMP_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid)); if (!$imp_mailbox->isValidIndex()) { _returnToMailbox(null, 'message_missing'); require IMP_BASE . '/mailbox.php'; @@ -61,7 +61,7 @@ if ($vars->actionID) { } /* Determine if mailbox is readonly. */ -$peek = $readonly = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->isReadOnly(IMP::$mailbox); +$peek = $readonly = $injector->getInstance('IMP_Factory_Imap')->create()->isReadOnly(IMP::$mailbox); /* Get mailbox/UID of message. */ $index_array = $imp_mailbox->getIMAPIndex(); @@ -211,7 +211,7 @@ $uid = $index_array['uid']; /* Parse the message. */ try { - $imp_contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($imp_mailbox)); + $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imp_mailbox)); } catch (IMP_Exception $e) { $imp_mailbox->removeMsgs(true); _returnToMailbox(null, 'message_missing'); @@ -223,10 +223,10 @@ try { try { /* Need to fetch flags before HEADERTEXT, because SEEN flag might be set * before we can grab it. */ - $flags_ret = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($mailbox_name, array( + $flags_ret = $injector->getInstance('IMP_Factory_Imap')->create()->fetch($mailbox_name, array( Horde_Imap_Client::FETCH_FLAGS => true, ), array('ids' => array($uid))); - $fetch_ret = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->fetch($mailbox_name, array( + $fetch_ret = $injector->getInstance('IMP_Factory_Imap')->create()->fetch($mailbox_name, array( Horde_Imap_Client::FETCH_ENVELOPE => true, Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => $peek)) ), array('ids' => array($uid))); @@ -473,7 +473,7 @@ if (!$use_pop) { $n_template->set('flaglist_set', $form_set); $n_template->set('flaglist_unset', $form_unset); - if ($injector->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { + if ($injector->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget moveAction', '', '', _("Move"), true)); $n_template->set('copy', Horde::widget('#', _("Copy to folder"), 'widget copyAction', '', '', _("Copy"), true)); $n_template->set('options', IMP::flistSelect(array('heading' => _("This message to"), 'new_folder' => true, 'inc_tasklists' => true, 'inc_notepads' => true))); diff --git a/imp/mobile.php b/imp/mobile.php index 48330fee1..ada77aebb 100644 --- a/imp/mobile.php +++ b/imp/mobile.php @@ -22,7 +22,7 @@ require $registry->get('templates', 'horde') . '/common-header-mobile.inc'; $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/mobile')); new Horde_View_Helper_Text($view); -if (!$injector->getInstance('IMP_Injector_Factory_Imap')->create()->allowFolders()) { +if (!$injector->getInstance('IMP_Factory_Imap')->create()->allowFolders()) { $view->allowFolders = false; } else { $view->allowFolders = true; diff --git a/imp/pgp.php b/imp/pgp.php index 4cc7eb7e8..eb44e1f56 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -158,7 +158,7 @@ case 'info_personal_private_key': case 'save_attachment_public_key': /* Retrieve the key from the message. */ - $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid)); + $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid)); $mime_part = $contents->getMIMEPart($vars->mime_id); if (empty($mime_part)) { throw new IMP_Exception('Cannot retrieve public key from message.'); diff --git a/imp/rss.php b/imp/rss.php index b5cc21bab..cf6d8c03c 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -46,7 +46,7 @@ if (!empty($request)) { $new_mail = (isset($request_parts[1]) && ($request_parts[1] === 'new')); } -$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create($mailbox); +$imp_mailbox = $injector->getInstance('IMP_Factory_MailboxList')->create($mailbox); $imp_search = $injector->getInstance('IMP_Search'); /* Obtain some information describing the mailbox state. */ diff --git a/imp/saveimage.php b/imp/saveimage.php index 1cb8cf566..11be59db6 100644 --- a/imp/saveimage.php +++ b/imp/saveimage.php @@ -21,7 +21,7 @@ $vars = Horde_Variables::getDefaultVariables(); /* Run through the action handlers. */ switch ($vars->actionID) { case 'save_image': - $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($vars->mbox, $vars->uid)); + $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($vars->mbox, $vars->uid)); $mime_part = $contents->getMIMEPart($vars->id); $image_data = array( 'data' => $mime_part->getContents(), diff --git a/imp/smime.php b/imp/smime.php index 6175c704f..3249ade86 100644 --- a/imp/smime.php +++ b/imp/smime.php @@ -102,7 +102,7 @@ case 'process_import_personal_certs': case 'save_attachment_public_key': /* Retrieve the key from the message. */ - $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid)); + $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid)); $mime_part = $contents->getMIMEPart($vars->mime_id); if (empty($mime_part)) { throw new IMP_Exception(_("Cannot retrieve public key from message.")); diff --git a/imp/templates/dimp/index.inc b/imp/templates/dimp/index.inc index 575d1ad00..11af1db1b 100644 --- a/imp/templates/dimp/index.inc +++ b/imp/templates/dimp/index.inc @@ -14,7 +14,7 @@ $use_trash = $prefs->getValue('use_trash'); $has_blacklist = $registry->hasMethod('mail/blacklistFrom'); $has_whitelist = $registry->hasMethod('mail/whitelistFrom'); -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); // Quota information $show_quota = $session->get('imp', 'imap_quota') diff --git a/imp/thread.php b/imp/thread.php index 895f01c5c..1a4b31037 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -28,8 +28,8 @@ $mode = $vars->mode ? $vars->mode : 'thread'; -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); -$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid)); +$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); +$imp_mailbox = $injector->getInstance('IMP_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid)); $error = false; if ($mode == 'thread') { @@ -95,7 +95,7 @@ foreach ($imp_indices->indices() as $mbox => $idxlist) { /* Get the body of the message. */ $curr_msg = $curr_tree = array(); - $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); + $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($mbox, $idx)); $mime_id = $contents->findBody(); if ($contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE)) { $ret = $contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE); diff --git a/imp/view.php b/imp/view.php index 1fc717e88..619767aa1 100644 --- a/imp/view.php +++ b/imp/view.php @@ -57,7 +57,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 = $injector->getInstance('IMP_Injector_Factory_Compose')->create($vars->composeCache); + $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($vars->composeCache); $mime = $imp_compose->buildAttachment($vars->id); $mime->setMimeId($vars->id); @@ -68,7 +68,7 @@ if ($vars->actionID == 'compose_attach_preview') { if (!$vars->uid || !$vars->mailbox) { exit; } - $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid)); + $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid)); } /* Run through action handlers */ diff --git a/jonah/lib/Application.php b/jonah/lib/Application.php index 1506cd805..feff5318b 100644 --- a/jonah/lib/Application.php +++ b/jonah/lib/Application.php @@ -35,7 +35,7 @@ class Jonah_Application extends Horde_Registry_Application */ protected function _init() { - $GLOBALS['injector']->bindFactory('Jonah_Driver', 'Jonah_Injector_Factory_Driver', 'create'); + $GLOBALS['injector']->bindFactory('Jonah_Driver', 'Jonah_Factory_Driver', 'create'); if ($channel_id = Horde_Util::getFormData('channel_id')) { $url = Horde::url('delivery/rss.php', true, -1) diff --git a/jonah/lib/Factory/Driver.php b/jonah/lib/Factory/Driver.php new file mode 100644 index 000000000..b760dc526 --- /dev/null +++ b/jonah/lib/Factory/Driver.php @@ -0,0 +1,70 @@ + + * @author Ben Klang + * @package Jonah + */ +class Jonah_Factory_Driver +{ + /** + * 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 driver instance. + * + * @param string $driver The concrete driver to return + * @param array $params An array of additional driver parameters. + * + * @return Jonah_Driver + * @throws Jonah_Exception + */ + public function create() + { + $driver = Horde_String::ucfirst($GLOBALS['conf']['news']['storage']['driver']); + $driver = basename($driver); + $params = Horde::getDriverConfig(array('news', 'storage'), $driver); + + $sig = md5($driver . serialize($params)); + if (isset($this->_instances[$sig])) { + return $this->_instances[$sig]; + } + + $class = 'Jonah_Driver_' . $driver; + if (class_exists($class)) { + $object = new $class($params); + $this->_instances[$sig] = $object; + } else { + throw new Jonah_Exception(sprintf(_("No such backend \"%s\" found"), $driver)); + } + + return $this->_instances[$sig]; + } +} diff --git a/jonah/lib/Injector/Factory/Driver.php b/jonah/lib/Injector/Factory/Driver.php deleted file mode 100644 index aba88bf8e..000000000 --- a/jonah/lib/Injector/Factory/Driver.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @author Ben Klang - * @package Jonah - */ -class Jonah_Injector_Factory_Driver -{ - /** - * 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 driver instance. - * - * @param string $driver The concrete driver to return - * @param array $params An array of additional driver parameters. - * - * @return Jonah_Driver - * @throws Jonah_Exception - */ - public function create() - { - $driver = Horde_String::ucfirst($GLOBALS['conf']['news']['storage']['driver']); - $driver = basename($driver); - $params = Horde::getDriverConfig(array('news', 'storage'), $driver); - - $sig = md5($driver . serialize($params)); - if (isset($this->_instances[$sig])) { - return $this->_instances[$sig]; - } - - $class = 'Jonah_Driver_' . $driver; - if (class_exists($class)) { - $object = new $class($params); - $this->_instances[$sig] = $object; - } else { - throw new Jonah_Exception(sprintf(_("No such backend \"%s\" found"), $driver)); - } - - return $this->_instances[$sig]; - } -} \ No newline at end of file diff --git a/kronolith/lib/Ajax/Application.php b/kronolith/lib/Ajax/Application.php index bff402dc7..97e07fb4e 100644 --- a/kronolith/lib/Ajax/Application.php +++ b/kronolith/lib/Ajax/Application.php @@ -850,7 +850,7 @@ class Kronolith_Ajax_Application extends Horde_Core_Ajax_Application $result = new stdClass; try { - $driver = $GLOBALS['injector']->getInstance('Kronolith_Injector_Factory_Driver')->create('Ical', $params); + $driver = $GLOBALS['injector']->getInstance('Kronolith_Factory_Driver')->create('Ical', $params); $driver->open($this->_vars->url); $ical = $driver->getRemoteCalendar(false); $result->success = true; diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index 08b182b32..950141870 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -72,7 +72,7 @@ class Kronolith_Application extends Horde_Registry_Application throw new Horde_Exception('The Content_Tagger class could not be found. Make sure the registry entry for the Content system is present.'); } - $GLOBALS['injector']->bindFactory('Kronolith_Geo', 'Kronolith_Injector_Factory_Geo', 'create'); + $GLOBALS['injector']->bindFactory('Kronolith_Geo', 'Kronolith_Factory_Geo', 'create'); /* Set the timezone variable, if available. */ $GLOBALS['registry']->setTimeZone(); diff --git a/kronolith/lib/Factory/Driver.php b/kronolith/lib/Factory/Driver.php new file mode 100644 index 000000000..ac67b5563 --- /dev/null +++ b/kronolith/lib/Factory/Driver.php @@ -0,0 +1,63 @@ +_injector = $injector; + } + + /** + * Return the driver instance. + * + * @param string $driver The storage backend to use + * @param array $params Driver params + * + * @return Kronolith_Driver + * @throws Kronolith_Exception + */ + public function create($driver, $params = array()) + { + $driver = basename($driver); + if (!empty($this->_instances[$driver])) { + return $this->_instances[$driver]; + } + $key = $driver; + $class = 'Kronolith_Driver_' . $driver; + if (class_exists($class)) { + $driver = new $class($params); + try { + $driver->initialize(); + } catch (Exception $e) { + $driver = new Kronolith_Driver($params, sprintf(_("The Calendar backend is not currently available: %s"), $e->getMessage())); + } + } else { + $driver = new Kronolith_Driver($params, sprintf(_("Unable to load the definition of %s."), $class)); + } + $this->_instances[$key] = $driver; + + return $driver; + } + +} diff --git a/kronolith/lib/Factory/Geo.php b/kronolith/lib/Factory/Geo.php new file mode 100644 index 000000000..73fe6243d --- /dev/null +++ b/kronolith/lib/Factory/Geo.php @@ -0,0 +1,38 @@ + + * @package Kronolith + */ +class Kronolith_Factory_Geo +{ + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * Return the driver instance. + * + * @return Kronolith_Storage + * @throws Kronolith_Exception + */ + public function create(Horde_Injector $injector) + { + if (empty($this->_instances[$GLOBALS['conf']['maps']['geodriver']])) { + if (!empty($GLOBALS['conf']['maps']['geodriver'])) { + $class = 'Kronolith_Geo_' . $GLOBALS['conf']['maps']['geodriver']; + $db = $injector->getInstance('Horde_Db_Adapter'); + $this->_instances[$GLOBALS['conf']['maps']['geodriver']] = new $class($db); + } else { + throw new Kronolith_Exception(_("Geospatial support not configured.")); + } + } + + return $this->_instances[$GLOBALS['conf']['maps']['geodriver']]; + } + +} diff --git a/kronolith/lib/Factory/Storage.php b/kronolith/lib/Factory/Storage.php new file mode 100644 index 000000000..ba88b4281 --- /dev/null +++ b/kronolith/lib/Factory/Storage.php @@ -0,0 +1,80 @@ +_injector = $injector; + } + + /** + * Return the driver instance. + * + * @return Kronolith_Storage + * @throws Kronolith_Exception + */ + public function create($params = array()) + { + if (empty($params['user'])) { + $user = $GLOBALS['registry']->getAuth(); + } else { + $user = $params['user']; + unset($params['user']); + } + + if (empty($params['driver'])) { + $driver = Horde_String::ucfirst($GLOBALS['conf']['storage']['driver']); + } else { + $driver = $params['driver']; + unset($params['driver']); + } + $driver = basename($driver); + $class = 'Kronolith_Storage_' . $driver; + + $driver_params = Horde::getDriverConfig('storage', 'Sql'); + if ($driver == 'Sql') { + if ($driver_params != 'Horde') { + // Custom DB config + $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('kronolith', Horde::getDriverConfig('storage', 'Sql')); + } else { + // Horde default DB config + $params['db'] = $this->_injector->getInstance('Horde_Db_Adapter'); + } + $params['table'] = $driver_params['table']; + } + + if (class_exists($class)) { + $driver = new $class($user, $params); + } else { + throw new Kronolith_Exception(sprintf(_("Unable to load the definition of %s."), $class)); + } + + try { + $driver->initialize(); + } catch (Exception $e) { + $driver = new Kronolith_Storage($params); + } + + return $driver; + } + +} diff --git a/kronolith/lib/FreeBusy.php b/kronolith/lib/FreeBusy.php index 4d4bef077..2c99ae736 100644 --- a/kronolith/lib/FreeBusy.php +++ b/kronolith/lib/FreeBusy.php @@ -209,7 +209,7 @@ class Kronolith_FreeBusy } /* Check storage driver. */ - $storage = $GLOBALS['injector']->getInstance('Kronolith_Injector_Factory_Storage')->create(); + $storage = $GLOBALS['injector']->getInstance('Kronolith_Factory_Storage')->create(); try { $fb = $storage->search($email); diff --git a/kronolith/lib/Injector/Factory/Driver.php b/kronolith/lib/Injector/Factory/Driver.php deleted file mode 100644 index d8ea70f1d..000000000 --- a/kronolith/lib/Injector/Factory/Driver.php +++ /dev/null @@ -1,63 +0,0 @@ -_injector = $injector; - } - - /** - * Return the driver instance. - * - * @param string $driver The storage backend to use - * @param array $params Driver params - * - * @return Kronolith_Driver - * @throws Kronolith_Exception - */ - public function create($driver, $params = array()) - { - $driver = basename($driver); - if (!empty($this->_instances[$driver])) { - return $this->_instances[$driver]; - } - $key = $driver; - $class = 'Kronolith_Driver_' . $driver; - if (class_exists($class)) { - $driver = new $class($params); - try { - $driver->initialize(); - } catch (Exception $e) { - $driver = new Kronolith_Driver($params, sprintf(_("The Calendar backend is not currently available: %s"), $e->getMessage())); - } - } else { - $driver = new Kronolith_Driver($params, sprintf(_("Unable to load the definition of %s."), $class)); - } - $this->_instances[$key] = $driver; - - return $driver; - } - -} \ No newline at end of file diff --git a/kronolith/lib/Injector/Factory/Geo.php b/kronolith/lib/Injector/Factory/Geo.php deleted file mode 100644 index 56e8e4abc..000000000 --- a/kronolith/lib/Injector/Factory/Geo.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @package Kronolith - */ -class Kronolith_Injector_Factory_Geo -{ - /** - * Instances. - * - * @var array - */ - private $_instances = array(); - - /** - * Return the driver instance. - * - * @return Kronolith_Storage - * @throws Kronolith_Exception - */ - public function create(Horde_Injector $injector) - { - if (empty($this->_instances[$GLOBALS['conf']['maps']['geodriver']])) { - if (!empty($GLOBALS['conf']['maps']['geodriver'])) { - $class = 'Kronolith_Geo_' . $GLOBALS['conf']['maps']['geodriver']; - $db = $injector->getInstance('Horde_Db_Adapter'); - $this->_instances[$GLOBALS['conf']['maps']['geodriver']] = new $class($db); - } else { - throw new Kronolith_Exception(_("Geospatial support not configured.")); - } - } - - return $this->_instances[$GLOBALS['conf']['maps']['geodriver']]; - } - -} \ No newline at end of file diff --git a/kronolith/lib/Injector/Factory/Storage.php b/kronolith/lib/Injector/Factory/Storage.php deleted file mode 100644 index b2174a4cc..000000000 --- a/kronolith/lib/Injector/Factory/Storage.php +++ /dev/null @@ -1,80 +0,0 @@ -_injector = $injector; - } - - /** - * Return the driver instance. - * - * @return Kronolith_Storage - * @throws Kronolith_Exception - */ - public function create($params = array()) - { - if (empty($params['user'])) { - $user = $GLOBALS['registry']->getAuth(); - } else { - $user = $params['user']; - unset($params['user']); - } - - if (empty($params['driver'])) { - $driver = Horde_String::ucfirst($GLOBALS['conf']['storage']['driver']); - } else { - $driver = $params['driver']; - unset($params['driver']); - } - $driver = basename($driver); - $class = 'Kronolith_Storage_' . $driver; - - $driver_params = Horde::getDriverConfig('storage', 'Sql'); - if ($driver == 'Sql') { - if ($driver_params != 'Horde') { - // Custom DB config - $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('kronolith', Horde::getDriverConfig('storage', 'Sql')); - } else { - // Horde default DB config - $params['db'] = $this->_injector->getInstance('Horde_Db_Adapter'); - } - $params['table'] = $driver_params['table']; - } - - if (class_exists($class)) { - $driver = new $class($user, $params); - } else { - throw new Kronolith_Exception(sprintf(_("Unable to load the definition of %s."), $class)); - } - - try { - $driver->initialize(); - } catch (Exception $e) { - $driver = new Kronolith_Storage($params); - } - - return $driver; - } - -} \ No newline at end of file diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 670b5e695..0fe7c1c21 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -2753,7 +2753,7 @@ class Kronolith break; } - self::$_instances[$driver] = $GLOBALS['injector']->getInstance('Kronolith_Injector_Factory_Driver')->create($driver, $params); + self::$_instances[$driver] = $GLOBALS['injector']->getInstance('Kronolith_Factory_Driver')->create($driver, $params); } if (!is_null($calendar)) { diff --git a/turba/add.php b/turba/add.php index 734200e6b..d6dbf8976 100644 --- a/turba/add.php +++ b/turba/add.php @@ -34,7 +34,7 @@ if (!$addSources) { /* A source has been selected, connect and set up the fields. */ if ($source) { try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($source); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); $driver = null; diff --git a/turba/contact.php b/turba/contact.php index 56c747af3..6f3342180 100644 --- a/turba/contact.php +++ b/turba/contact.php @@ -22,7 +22,7 @@ if (!isset($GLOBALS['cfgSources'][$source])) { /* Set the contact from the key requested. */ try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($source); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); Horde::url($prefs->getValue('initial_page'), true)->redirect(); diff --git a/turba/data.php b/turba/data.php index e635a3036..eee4ec084 100644 --- a/turba/data.php +++ b/turba/data.php @@ -242,7 +242,7 @@ case 'export': foreach ($sources as $source => $objectkeys) { /* Create a Turba storage instance. */ try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($source); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); $error = true; @@ -335,7 +335,7 @@ case 'export': case Horde_Data::IMPORT_FILE: $dest = Horde_Util::getFormData('dest'); try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($dest); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($dest); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); $error = true; @@ -423,7 +423,7 @@ if (is_array($next_step)) { /* Create a Turba storage instance. */ $dest = $session->get('horde', 'import_data/target'); try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($dest); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($dest); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); $driver = null; diff --git a/turba/delete.php b/turba/delete.php index 8f37d8649..4628413ea 100644 --- a/turba/delete.php +++ b/turba/delete.php @@ -18,7 +18,7 @@ Horde_Registry::appInit('turba'); $source = Horde_Util::getFormData('source'); $key = Horde_Util::getFormData('key'); -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($source); if ($conf['documents']['type'] != 'none') { try { diff --git a/turba/deletefile.php b/turba/deletefile.php index 778499ee9..ff4d495d5 100644 --- a/turba/deletefile.php +++ b/turba/deletefile.php @@ -23,7 +23,7 @@ if ($source === null || !isset($cfgSources[$source])) { Horde::url($prefs->getValue('initial_page'), true)->redirect(); } -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($source); try { $contact = $driver->getObject(Horde_Util::getPost('key')); diff --git a/turba/edit.php b/turba/edit.php index b60ccfb29..d0335e963 100644 --- a/turba/edit.php +++ b/turba/edit.php @@ -45,7 +45,7 @@ if ($source === null || !isset($cfgSources[$source])) { $url->redirect(); } -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($source); /* Set the contact from the requested key. */ try { diff --git a/turba/lib/Api.php b/turba/lib/Api.php index f23e902df..bc6ae861f 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -51,7 +51,7 @@ class Turba_Api extends Horde_Registry_Api @list($source, $key) = explode('.', $id, 2); if (isset($GLOBALS['cfgSources'][$source]) && $key) { try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $object = $driver->getObject($key)->getValue('name'); } catch (Turba_Exception $e) {} } @@ -134,7 +134,7 @@ class Turba_Api extends Horde_Registry_Api } try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($params['source']); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($params['source']); if ($driver->checkDefaultShare($share, $cfgSources[$params['source']])) { return $uid; } @@ -322,7 +322,7 @@ class Turba_Api extends Horde_Registry_Api } // Load the Turba driver. - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($parts[1]); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($parts[1]); $contacts = $driver->search(array()); @@ -371,7 +371,7 @@ class Turba_Api extends Horde_Registry_Api } // Load the Turba driver. - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($parts[1]); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($parts[1]); $contact = $driver->getObject($parts[2]); @@ -418,7 +418,7 @@ class Turba_Api extends Horde_Registry_Api } // Load the Turba driver. - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($parts[1]); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($parts[1]); return $driver->delete($parts[2]); } @@ -458,7 +458,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source)); } - $storage = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $storage = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); try { $results = $storage->search(array()); @@ -518,7 +518,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source)); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $histories = $history->getByTimestamp( '>', $timestamp, $filter, @@ -589,7 +589,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source)); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $ts = $history->getActionTimestamp('turba:' . $driver->getName() . ':' . $uid, @@ -635,7 +635,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $import_source)); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($import_source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($import_source); if (!$driver->hasPermission(Horde_Perms::EDIT)) { throw new Turba_Exception(_("Permission denied")); @@ -763,7 +763,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(_("Invalid ID")); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); if (!$driver->hasPermission(Horde_Perms::READ)) { continue; @@ -827,7 +827,7 @@ class Turba_Api extends Horde_Registry_Api public function ownVCard() { $contact = $this->getOwnContactObject(); - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($contact['source']); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($contact['source']); $vcard = $driver->tovCard($contact['contact'], '3.0', null, true); $vcard->setAttribute('VERSION', '3.0'); @@ -868,7 +868,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(_("The address book with your own contact doesn't exist anymore.")); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); if (!$driver->hasPermission(Horde_Perms::READ)) { throw new Turba_Exception(_("You don't have sufficient permissions to read the address book that contains your own contact.")); @@ -933,7 +933,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(_("Invalid ID")); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); if (!$GLOBALS['registry']->isAdmin() && !$driver->hasPermission(Horde_Perms::DELETE)) { @@ -996,7 +996,7 @@ class Turba_Api extends Horde_Registry_Api } // Check permissions. - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); if (!$driver->hasPermission(Horde_Perms::EDIT)) { continue; } @@ -1121,7 +1121,7 @@ class Turba_Api extends Horde_Registry_Api continue; } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); // Determine the name of the column to sort by. $columns = isset($sort_columns[$source]) @@ -1274,7 +1274,7 @@ class Turba_Api extends Horde_Registry_Api } if (isset($cfgSources[$source])) { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $object = $driver->getObject($objectId); @@ -1310,7 +1310,7 @@ class Turba_Api extends Horde_Registry_Api } if (isset($cfgSources[$source])) { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $objects = $driver->getObjects($objectIds); @@ -1351,7 +1351,7 @@ class Turba_Api extends Horde_Registry_Api $results = array(); foreach ($sources as $source) { if (isset($cfgSources[$source])) { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $res = $driver->search(array()); if (!($res instanceof Turba_List)) { @@ -1419,7 +1419,7 @@ class Turba_Api extends Horde_Registry_Api $objects = array(); foreach ($time_categories as $category) { list($category, $source) = explode('/', $category, 2); - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $objects = array_merge($objects, $driver->listTimeObjects($start, $end, $category)); } @@ -1563,7 +1563,7 @@ class Turba_Api extends Horde_Registry_Api throw new Turba_Exception(_("Invalid entry")); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); if (!$driver->hasPermission(Horde_Perms::EDIT)) { throw new Turba_Exception(_("Permission denied")); @@ -1654,7 +1654,7 @@ class Turba_Api extends Horde_Registry_Api continue; } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $criterium = array('email' => $address); if (!isset($driver->map['email'])) { if (isset($driver->map['emails'])) { @@ -1719,7 +1719,7 @@ class Turba_Api extends Horde_Registry_Api foreach ($sources as $source) { if (isset($cfgSources[$source])) { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); if (!$driver->hasPermission(Horde_Perms::EDIT)) { continue; } diff --git a/turba/lib/Application.php b/turba/lib/Application.php index a42b0182e..463d14e44 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -400,7 +400,7 @@ class Turba_Application extends Horde_Registry_Application if (empty($source['use_shares'])) { // Shares not enabled for this source try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); } catch (Turba_Exception $e) { Horde::logMessage($e, 'ERR'); throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user)); @@ -433,7 +433,7 @@ class Turba_Application extends Horde_Registry_Application if (!empty($params['default'])) { $config = Turba::getSourceFromShare($share); try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($config); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($config); } catch (Turba_Exception $e) { continue; } diff --git a/turba/lib/Driver/Share.php b/turba/lib/Driver/Share.php index 57023a598..da5f2e820 100644 --- a/turba/lib/Driver/Share.php +++ b/turba/lib/Driver/Share.php @@ -44,7 +44,7 @@ class Turba_Driver_Share extends Turba_Driver { parent::__construct($name, $params); $this->_share = $this->_params['config']['params']['share']; - $this->_driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($this->_params['config']); + $this->_driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_params['config']); } /** diff --git a/turba/lib/Driver/Vbook.php b/turba/lib/Driver/Vbook.php index 0aea11519..afffabe13 100644 --- a/turba/lib/Driver/Vbook.php +++ b/turba/lib/Driver/Vbook.php @@ -41,7 +41,7 @@ class Turba_Driver_Vbook extends Turba_Driver $this->_share = $this->_params['share']; /* Load the underlying driver. */ - $this->_driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($this->_params['source']); + $this->_driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_params['source']); $this->searchCriteria = empty($this->_params['criteria']) ? array() diff --git a/turba/lib/Factory/Driver.php b/turba/lib/Factory/Driver.php new file mode 100644 index 000000000..168a66952 --- /dev/null +++ b/turba/lib/Factory/Driver.php @@ -0,0 +1,140 @@ + + * @category Horde + * @license http://www.horde.org/licenses/apl.html APL + * @link http://pear.horde.org/index.php?package=Turba + * @package Turba + */ + +/** + * A Horde_Injector:: based Turba_Driver:: factory. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (APL). If you + * did not receive this file, see http://www.horde.org/licenses/apl.html. + * + * @author Michael Slusarz + * @category Horde + * @license http://www.horde.org/licenses/apl.html APL + * @link http://pear.horde.org/index.php?package=Turba + * @package Turba + */ +class Turba_Factory_Driver +{ + /** + * 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 Turba_Driver:: instance. + * + * @param mixed $name Either a string containing the internal name of this + * source, or a config array describing the source. + * + * @return Turba_Driver The singleton instance. + * @throws Turba_Exception + */ + public function create($name) + { + if (is_array($name)) { + $key = md5(serialize($name)); + $srcName = ''; + $srcConfig = $name; + } else { + $key = $name; + $srcName = $name; + if (empty($GLOBALS['cfgSources'][$name])) { + throw new Turba_Exception(sprintf(_("The address book \"%s\" does not exist."), $name)); + } + $srcConfig = $GLOBALS['cfgSources'][$name]; + } + + if (!isset($this->_instances[$key])) { + $class = 'Turba_Driver_' . ucfirst(basename($srcConfig['type'])); + if (!class_exists($class)) { + throw new Turba_Exception(sprintf(_("Unable to load the definition of %s."), $class)); + } + + if (empty($srcConfig['params'])) { + $srcConfig['params'] = array(); + } + + switch ($class) { + case 'Turba_Driver_Sql': + try { + $srcConfig['params']['db'] = empty($srcConfig['params']['sql']) + ? $GLOBALS['injector']->getInstance('Horde_Db_Adapter') + : $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('turba', $this->_params['sql']); + } catch (Horde_Db_Exception $e) { + throw new Turba_Exception($e); + } + break; + } + + $driver = new $class($srcName, $srcConfig['params']); + + // Title + $driver->title = $srcConfig['title']; + + /* Initialize */ + //$driver->_init(); + + /* Store and translate the map at the Source level. */ + $driver->map = $srcConfig['map']; + foreach ($driver->map as $key => $val) { + if (!is_array($val)) { + $driver->fields[$key] = $val; + } + } + + /* Store tabs. */ + if (isset($srcConfig['tabs'])) { + $driver->tabs = $srcConfig['tabs']; + } + + /* Store remaining fields. */ + if (isset($srcConfig['strict'])) { + $driver->strict = $srcConfig['strict']; + } + if (isset($srcConfig['approximate'])) { + $driver->approximate = $srcConfig['approximate']; + } + if (isset($srcConfig['list_name_field'])) { + $driver->listNameField = $srcConfig['list_name_field']; + } + if (isset($srcConfig['alternative_name'])) { + $driver->alternativeName = $srcConfig['alternative_name']; + } + $this->_instances[$key] = $driver; + } + + return $this->_instances[$key]; + } + +} diff --git a/turba/lib/Form/CreateAddressBook.php b/turba/lib/Form/CreateAddressBook.php index c0a6befae..985d24500 100644 --- a/turba/lib/Form/CreateAddressBook.php +++ b/turba/lib/Form/CreateAddressBook.php @@ -35,7 +35,7 @@ class Turba_Form_CreateAddressBook extends Horde_Form // Need a clean cfgSources array include TURBA_BASE . '/config/backends.php'; - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($cfgSources[$GLOBALS['conf']['shares']['source']]); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($cfgSources[$GLOBALS['conf']['shares']['source']]); $params = array( 'params' => array('source' => $GLOBALS['conf']['shares']['source']), diff --git a/turba/lib/Form/DeleteAddressBook.php b/turba/lib/Form/DeleteAddressBook.php index 3bae3e77e..6fe2f91e6 100644 --- a/turba/lib/Form/DeleteAddressBook.php +++ b/turba/lib/Form/DeleteAddressBook.php @@ -50,7 +50,7 @@ class Turba_Form_DeleteAddressBook extends Horde_Form throw new Turba_Exception(_("You do not have permissions to delete this address book.")); } - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($this->_addressbook->getName()); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_addressbook->getName()); // We have a Turba_Driver, try to delete the address book. $driver->deleteAll(); diff --git a/turba/lib/Injector/Factory/Driver.php b/turba/lib/Injector/Factory/Driver.php deleted file mode 100644 index 74ce00aa8..000000000 --- a/turba/lib/Injector/Factory/Driver.php +++ /dev/null @@ -1,140 +0,0 @@ - - * @category Horde - * @license http://www.horde.org/licenses/apl.html APL - * @link http://pear.horde.org/index.php?package=Turba - * @package Turba - */ - -/** - * A Horde_Injector:: based Turba_Driver:: factory. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (APL). If you - * did not receive this file, see http://www.horde.org/licenses/apl.html. - * - * @author Michael Slusarz - * @category Horde - * @license http://www.horde.org/licenses/apl.html APL - * @link http://pear.horde.org/index.php?package=Turba - * @package Turba - */ -class Turba_Injector_Factory_Driver -{ - /** - * 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 Turba_Driver:: instance. - * - * @param mixed $name Either a string containing the internal name of this - * source, or a config array describing the source. - * - * @return Turba_Driver The singleton instance. - * @throws Turba_Exception - */ - public function create($name) - { - if (is_array($name)) { - $key = md5(serialize($name)); - $srcName = ''; - $srcConfig = $name; - } else { - $key = $name; - $srcName = $name; - if (empty($GLOBALS['cfgSources'][$name])) { - throw new Turba_Exception(sprintf(_("The address book \"%s\" does not exist."), $name)); - } - $srcConfig = $GLOBALS['cfgSources'][$name]; - } - - if (!isset($this->_instances[$key])) { - $class = 'Turba_Driver_' . ucfirst(basename($srcConfig['type'])); - if (!class_exists($class)) { - throw new Turba_Exception(sprintf(_("Unable to load the definition of %s."), $class)); - } - - if (empty($srcConfig['params'])) { - $srcConfig['params'] = array(); - } - - switch ($class) { - case 'Turba_Driver_Sql': - try { - $srcConfig['params']['db'] = empty($srcConfig['params']['sql']) - ? $GLOBALS['injector']->getInstance('Horde_Db_Adapter') - : $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('turba', $this->_params['sql']); - } catch (Horde_Db_Exception $e) { - throw new Turba_Exception($e); - } - break; - } - - $driver = new $class($srcName, $srcConfig['params']); - - // Title - $driver->title = $srcConfig['title']; - - /* Initialize */ - //$driver->_init(); - - /* Store and translate the map at the Source level. */ - $driver->map = $srcConfig['map']; - foreach ($driver->map as $key => $val) { - if (!is_array($val)) { - $driver->fields[$key] = $val; - } - } - - /* Store tabs. */ - if (isset($srcConfig['tabs'])) { - $driver->tabs = $srcConfig['tabs']; - } - - /* Store remaining fields. */ - if (isset($srcConfig['strict'])) { - $driver->strict = $srcConfig['strict']; - } - if (isset($srcConfig['approximate'])) { - $driver->approximate = $srcConfig['approximate']; - } - if (isset($srcConfig['list_name_field'])) { - $driver->listNameField = $srcConfig['list_name_field']; - } - if (isset($srcConfig['alternative_name'])) { - $driver->alternativeName = $srcConfig['alternative_name']; - } - $this->_instances[$key] = $driver; - } - - return $this->_instances[$key]; - } - -} diff --git a/turba/lib/List.php b/turba/lib/List.php index 978152617..ee07d8118 100644 --- a/turba/lib/List.php +++ b/turba/lib/List.php @@ -38,7 +38,7 @@ class Turba_List implements Countable foreach ($ids as $value) { list($source, $key) = explode(':', $value); try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); $this->insert($driver->getObject($key)); } catch (Turba_Exception $e) {} } diff --git a/turba/lib/LoginTasks/SystemTask/UpgradeLists.php b/turba/lib/LoginTasks/SystemTask/UpgradeLists.php index 6c4adeb09..cdfc37770 100644 --- a/turba/lib/LoginTasks/SystemTask/UpgradeLists.php +++ b/turba/lib/LoginTasks/SystemTask/UpgradeLists.php @@ -40,7 +40,7 @@ class Turba_LoginTasks_SystemTask_UpgradeLists extends Horde_LoginTasks_SystemTa $sources = array_keys($GLOBALS['cfgSources']); foreach ($sources as $sourcekey) { try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourcekey); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($sourcekey); $lists = $driver->search($criteria); } catch (Turba_Exception $e) { return false; diff --git a/turba/lib/Object/Group.php b/turba/lib/Object/Group.php index b2502f1e2..9077442c5 100644 --- a/turba/lib/Object/Group.php +++ b/turba/lib/Object/Group.php @@ -69,7 +69,7 @@ class Turba_Object_Group extends Turba_Object if ($sourceId == $this->getSource()) { $contact = $this->driver->getObject($contactId); } else { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourceId); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($sourceId); $contact = $driver->getObject($contactId); } @@ -172,7 +172,7 @@ class Turba_Object_Group extends Turba_Object } try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourceId); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($sourceId); } catch (Turba_Exception $e) { continue; } diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index 48b0a9ad4..e94c84d7c 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -367,7 +367,7 @@ class Turba foreach ($in as $sourceId => $source) { try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourceId); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($sourceId); } catch (Turba_Exception $e) { Horde::logMessage($e, 'ERR'); continue; @@ -454,7 +454,7 @@ class Turba if ($GLOBALS['registry']->getAuth() && !$personal) { // User's default share is missing. try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($source); } catch (Turba_Exception $e) { $GLOBALS['notification']->push($driver, 'horde.error'); continue; diff --git a/turba/lib/View/Browse.php b/turba/lib/View/Browse.php index 9c69e7b79..75a15d7bd 100644 --- a/turba/lib/View/Browse.php +++ b/turba/lib/View/Browse.php @@ -68,7 +68,7 @@ class Turba_View_Browse } else { try { $driver = $GLOBALS['injector'] - ->getInstance('Turba_Injector_Factory_Driver') + ->getInstance('Turba_Factory_Driver') ->create($source); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); @@ -160,7 +160,7 @@ class Turba_View_Browse try { $targetDriver = $GLOBALS['injector'] - ->getInstance('Turba_Injector_Factory_Driver') + ->getInstance('Turba_Factory_Driver') ->create($targetSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); @@ -191,7 +191,7 @@ class Turba_View_Browse // Try and load the driver for the source. try { $sourceDriver = $GLOBALS['injector'] - ->getInstance('Turba_Injector_Factory_Driver') + ->getInstance('Turba_Factory_Driver') ->create($objectSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); @@ -303,7 +303,7 @@ class Turba_View_Browse try { $targetDriver = $GLOBALS['injector'] - ->getInstance('Turba_Injector_Factory_Driver') + ->getInstance('Turba_Factory_Driver') ->create($targetSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); @@ -320,7 +320,7 @@ class Turba_View_Browse $targetSource = $vars->get('targetAddressbook'); try { $targetDriver = $GLOBALS['injector'] - ->getInstance('Turba_Injector_Factory_Driver') + ->getInstance('Turba_Factory_Driver') ->create($targetSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); diff --git a/turba/lib/View/List.php b/turba/lib/View/List.php index 02020ebcb..5ac193db9 100644 --- a/turba/lib/View/List.php +++ b/turba/lib/View/List.php @@ -161,7 +161,7 @@ class Turba_View_List implements Countable global $prefs, $session, $default_source, $copymove_source_options; $driver = $GLOBALS['injector'] - ->getInstance('Turba_Injector_Factory_Driver') + ->getInstance('Turba_Factory_Driver') ->create($default_source); $hasDelete = $driver->hasPermission(Horde_Perms::DELETE); $hasEdit = $driver->hasPermission(Horde_Perms::EDIT); @@ -424,7 +424,7 @@ class Turba_View_List implements Countable 'name' => '  ' . htmlspecialchars($srcConfig['title']), 'source' => htmlspecialchars($src)); - $srcDriver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($src); + $srcDriver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($src); try { $listList = $srcDriver->search( array('__type' => 'Group'), diff --git a/turba/lib/tests/KolabTest.php b/turba/lib/tests/KolabTest.php index 38188c3f7..5a5e6e411 100644 --- a/turba/lib/tests/KolabTest.php +++ b/turba/lib/tests/KolabTest.php @@ -47,14 +47,14 @@ class Turba_KolabTest extends Turba_KolabTestBase { $this->_kolab->_storage->save($object); // Check that the driver can be created - $turba = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create('wrobel@example.org'); + $turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('wrobel@example.org'); //$this->assertNoError($turba); $result = $turba->search(array(), array('last-name')); $this->assertNoError($result); $this->assertEquals(2, count($result)); - $turba = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create('INBOX%2Ftest2'); + $turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('INBOX%2Ftest2'); $result = $turba->search(array(), array('last-name')); $this->assertEquals(0, count($result)); @@ -75,7 +75,7 @@ class Turba_KolabTest extends Turba_KolabTestBase { ); // Save the contact - $turba = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create('wrobel@example.org'); + $turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('wrobel@example.org'); //$this->assertNoError($turba); $this->assertNoError($turba->_add($object)); @@ -102,7 +102,7 @@ class Turba_KolabTest extends Turba_KolabTestBase { ); // Save the contact - $turba = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create('wrobel@example.org'); + $turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('wrobel@example.org'); //$this->assertNoError($turba); $this->assertNoError($turba->_add($object)); diff --git a/turba/merge.php b/turba/merge.php index b288a176b..deb7d30fc 100644 --- a/turba/merge.php +++ b/turba/merge.php @@ -16,7 +16,7 @@ Horde_Registry::appInit('turba'); $source = Horde_Util::getFormData('source'); $key = Horde_Util::getFormData('key'); $mergeInto = Horde_Util::getFormData('merge_into'); -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($source); if ($url = Horde_Util::getFormData('url')) { $url = new Horde_Url($url, true); diff --git a/turba/minisearch.php b/turba/minisearch.php index 66a7e2101..e304a0e90 100644 --- a/turba/minisearch.php +++ b/turba/minisearch.php @@ -22,7 +22,7 @@ $source = Horde_Util::getFormData('source', Turba::getDefaultAddressBook()); // Do the search if we have one. if (!is_null($search)) { try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($source); $criteria['name'] = trim($search); $res = $driver->search($criteria); diff --git a/turba/scripts/import_squirrelmail_file_abook.php b/turba/scripts/import_squirrelmail_file_abook.php index 5d848ebe9..53e6d2d07 100755 --- a/turba/scripts/import_squirrelmail_file_abook.php +++ b/turba/scripts/import_squirrelmail_file_abook.php @@ -83,7 +83,7 @@ foreach($files as $file) { // Initiate driver try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($import_source); + $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($import_source); } catch (Turba_Exception $e) { PEAR::raiseError(sprintf(_("Connection failed: %s"), $e->getMessage()), 'horde.error', null, null, $import_source); continue; diff --git a/turba/scripts/import_squirrelmail_sql_abook.php b/turba/scripts/import_squirrelmail_sql_abook.php index bc97bf7b9..5f370a68f 100755 --- a/turba/scripts/import_squirrelmail_sql_abook.php +++ b/turba/scripts/import_squirrelmail_sql_abook.php @@ -92,7 +92,7 @@ while ($row = $handle->fetchRow(DB_FETCHMODE_ASSOC)) { // Initiate driver try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($import_source); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($import_source); } catch (Turba_Exception $e) { $cli->message(' ' . sprintf(_("Connection failed: %s"), $e->getMessage()), 'cli.error'); continue; diff --git a/turba/scripts/upgrades/public_to_horde_share.php b/turba/scripts/upgrades/public_to_horde_share.php index e832fd937..5c55b240b 100755 --- a/turba/scripts/upgrades/public_to_horde_share.php +++ b/turba/scripts/upgrades/public_to_horde_share.php @@ -68,7 +68,7 @@ $share->save(); $CLI->message('Created new Horde_Share object for the shared address book.', 'cli.success'); // Share created, now get a Turba_Driver and make the changes. -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($sourceKey); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($sourceKey); $db = &$driver->_db; diff --git a/turba/search.php b/turba/search.php index 8238fdbeb..5e6d8b448 100644 --- a/turba/search.php +++ b/turba/search.php @@ -85,7 +85,7 @@ $val = Horde_Util::getFormData('val'); $action = Horde_Util::getFormData('actionID'); try { - $driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $injector->getInstance('Turba_Factory_Driver')->create($source); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); $driver = null; diff --git a/turba/vcard.php b/turba/vcard.php index eaa6c153e..417ee2fc5 100644 --- a/turba/vcard.php +++ b/turba/vcard.php @@ -19,7 +19,7 @@ if (!isset($cfgSources[$source])) { Horde::url($prefs->getValue('initial_page'), true)->redirect(); } -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($source); /* Set the contact from the key requested. */ try { diff --git a/turba/view.php b/turba/view.php index 377640afb..c2f9b5702 100644 --- a/turba/view.php +++ b/turba/view.php @@ -28,7 +28,7 @@ if (!isset($cfgSources[$source])) { throw new Turba_Exception(_("The contact you requested does not exist.")); } -$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source); +$driver = $injector->getInstance('Turba_Factory_Driver')->create($source); $object = $driver->getObject($key); /* Check permissions. */