--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based Horde_Kolab_Storage:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Core
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+
+/**
+ * A Horde_Injector:: based Horde_Kolab_Storage:: factory.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Core
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+class Horde_Core_Factory_KolabStorage
+{
+ /**
+ * 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;
+ $this->_setup();
+ }
+
+ /**
+ * Setup the machinery to create Horde_Kolab_Session objects.
+ *
+ * @return NULL
+ */
+ private function _setup()
+ {
+ $this->_setupConfiguration();
+ }
+
+ /**
+ * Provide configuration settings for Horde_Kolab_Session.
+ *
+ * @return NULL
+ */
+ private function _setupConfiguration()
+ {
+ $configuration = array();
+
+ //@todo: Update configuration parameters
+ if (!empty($GLOBALS['conf']['kolab']['imap'])) {
+ $configuration = $GLOBALS['conf']['kolab']['imap'];
+ }
+ if (!empty($GLOBALS['conf']['kolab']['storage'])) {
+ $configuration = $GLOBALS['conf']['kolab']['storage'];
+ }
+
+ $this->_injector->setInstance(
+ 'Horde_Kolab_Storage_Configuration', $configuration
+ );
+ }
+
+ /**
+ * Return the Horde_Kolab_Storage:: instance.
+ *
+ * @return Horde_Kolab_Storage The storage handler.
+ */
+ public function getStorage()
+ {
+ $configuration = $this->_injector->getInstance('Horde_Kolab_Storage_Configuration');
+
+ $session = $this->_injector->getInstance('Horde_Kolab_Session');
+
+ $mail = $session->getMail();
+ if (empty($mail)) {
+ return false;
+ }
+
+ return new Horde_Kolab_Storage(
+ 'Imap',
+ array(
+ 'hostspec' => $session->getImapServer(),
+ 'username' => Horde_Auth::getAuth(),
+ 'password' => Horde_Auth::getCredential('password'),
+ 'secure' => true
+ )
+ );
+ }
+}
$injector->addBinder('Net_DNS_Resolver', new Horde_Core_Binder_Dns());
$injector->bindFactory('Horde_Kolab_Server_Composite', 'Horde_Core_Factory_KolabServer', 'getComposite');
$injector->bindFactory('Horde_Kolab_Session', 'Horde_Core_Factory_KolabSession', 'getSession');
+ $injector->bindFactory('Horde_Kolab_Storage', 'Horde_Core_Factory_KolabStorage', 'getStorage');
$GLOBALS['registry'] = $this;
$injector->setInstance('Horde_Registry', $this);
}
/**
- * Attempts to return a reference to a concrete Horde_Kolab_Storage_List
- * instance based on $driver and $params. It will only create a new instance
- * if no Horde_Kolab_Storage_List instance with the same parameters currently
- * exists.
- *
- * This method must be invoked as:
- * $var = &Horde_Kolab_Storage_List::singleton()
- *
- * @param string $driver The driver used for the primary storage connection.
- * @param array $params Additional connection parameters.
- *
- * @return Horde_Kolab_Storage_List The concrete Horde_Kolab_Storage reference.
- */
- static public function singleton($driver, $params = array())
- {
- ksort($params);
- $signature = hash('md5', serialize(array($driver, $params)));
-
- if (!isset(self::$instances[$signature])) {
- self::$instances[$signature] = Horde_Kolab_Storage::factory($driver,
- $params);
- }
-
- return self::$instances[$signature];
- }
-
- /**
* Clean the simulated IMAP store.
*
* @return NULL
return $this->_type;
}
- $this->_list = $this->getSession()->getStorage();
+ $this->_list = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage');
parent::__wakeup();
}
- /**
- * Set the session handler.
- *
- * @param Horde_Kolab_Session $session The session handler.
- *
- * @return NULL
- */
- public function setSession(Horde_Kolab_Session $session)
- {
- $this->_session = $session;
- }
-
- /**
- * Retrieve a connected kolab session.
- *
- * @return Horde_Kolab_Session The connected session.
- *
- * @throws Horde_Kolab_Session_Exception
- */
- public function getSession()
- {
- if (!isset($this->_session)) {
- $this->_session = $GLOBALS['injector']->getInstance('Horde_Kolab_Session');
- }
- return $this->_session;
- }
-
private function _getFolderType($app)
{
switch ($app) {
}
/**
- * Set the session handler.
- *
- * @param Horde_Kolab_Session $session The session handler.
- *
- * @return NULL
- */
- public function setSession(Horde_Kolab_Session $session)
- {
- $this->_session = $session;
- }
-
- /**
- * Retrieve a connected kolab session.
- *
- * @return Horde_Kolab_Session The connected session.
- *
- * @throws Horde_Kolab_Session_Exception
- */
- public function getSession()
- {
- if (!isset($this->_session)) {
- $this->_session = $GLOBALS['injector']->getInstance('Horde_Kolab_Session');
- }
- return $this->_session;
- }
-
- /**
* Associates a Share object with this share.
*
* @param Horde_Share $shareOb The Share object.
*/
function __wakeup()
{
- $this->_list = $this->getSession()->getStorage();
+ $this->_list = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage');
if (isset($this->_folder_name)) {
$this->_folder = $this->_list->getFolder($this->_folder_name);
}
private $_store;
/**
- * Set the session handler.
- *
- * @param Horde_Kolab_Session $session The session handler.
- *
- * @return NULL
- */
- public function setSession(Horde_Kolab_Session $session)
- {
- $this->_session = $session;
- }
-
- /**
- * Retrieve a connected kolab session.
- *
- * @return Horde_Kolab_Session The connected session.
- *
- * @throws Horde_Kolab_Session_Exception
- */
- public function getSession()
- {
- if (!isset($this->_session)) {
- $this->_session = $GLOBALS['injector']->getInstance('Horde_Kolab_Session');
- }
- return $this->_session;
- }
-
- /**
* Attempts to open a Kolab Groupware folder.
*/
public function initialize()
{
- $this->_kolab = $this->getSession()->getStorage();
+ $this->_kolab = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage');
$this->reset();
}