Start the KolabStorage factory, remove the singleton pattern and start using the...
authorGunnar Wrobel <p@rdus.de>
Wed, 17 Mar 2010 18:54:30 +0000 (19:54 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Wed, 17 Mar 2010 20:23:33 +0000 (21:23 +0100)
framework/Core/lib/Horde/Core/Factory/KolabStorage.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage.php
framework/Share/Share/kolab.php
kronolith/lib/Driver/Kolab.php

diff --git a/framework/Core/lib/Horde/Core/Factory/KolabStorage.php b/framework/Core/lib/Horde/Core/Factory/KolabStorage.php
new file mode 100644 (file)
index 0000000..204db3b
--- /dev/null
@@ -0,0 +1,107 @@
+<?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
+            )
+        );
+    }
+}
index 4484364..1471cb8 100644 (file)
@@ -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);
index e3f40ad..6c0896b 100644 (file)
@@ -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
index 37eb9c8..af6cd49 100644 (file)
@@ -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);
         }
index be0d770..5edb7ad 100644 (file)
@@ -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();
     }