From: Gunnar Wrobel
Date: Wed, 17 Mar 2010 18:54:30 +0000 (+0100)
Subject: Start the KolabStorage factory, remove the singleton pattern and start using the...
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9cd9238e67c6e01ab095db6b87a028ef0638a92f;p=horde.git
Start the KolabStorage factory, remove the singleton pattern and start using the injector.
---
diff --git a/framework/Core/lib/Horde/Core/Factory/KolabStorage.php b/framework/Core/lib/Horde/Core/Factory/KolabStorage.php
new file mode 100644
index 000000000..204db3b4d
--- /dev/null
+++ b/framework/Core/lib/Horde/Core/Factory/KolabStorage.php
@@ -0,0 +1,107 @@
+
+ * @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
+ * @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
+ )
+ );
+ }
+}
diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php
index 4484364ad..1471cb813 100644
--- a/framework/Core/lib/Horde/Registry.php
+++ b/framework/Core/lib/Horde/Registry.php
@@ -240,6 +240,7 @@ class Horde_Registry
$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);
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php
index e3f40ad68..6c0896bd1 100644
--- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php
@@ -169,33 +169,6 @@ class Horde_Kolab_Storage
}
/**
- * 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
diff --git a/framework/Share/Share/kolab.php b/framework/Share/Share/kolab.php
index 37eb9c858..af6cd4940 100644
--- a/framework/Share/Share/kolab.php
+++ b/framework/Share/Share/kolab.php
@@ -61,38 +61,11 @@ class Horde_Share_kolab extends Horde_Share {
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) {
@@ -449,33 +422,6 @@ class Horde_Share_Object_kolab extends Horde_Share_Object {
}
/**
- * 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.
@@ -490,7 +436,7 @@ class Horde_Share_Object_kolab extends Horde_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);
}
diff --git a/kronolith/lib/Driver/Kolab.php b/kronolith/lib/Driver/Kolab.php
index be0d770b5..5edb7add8 100644
--- a/kronolith/lib/Driver/Kolab.php
+++ b/kronolith/lib/Driver/Kolab.php
@@ -50,38 +50,11 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
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();
}