Allow to validate a stored session.
authorGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 19:03:39 +0000 (20:03 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 19:03:39 +0000 (20:03 +0100)
framework/Kolab_Session/lib/Horde/Kolab/Session.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php
framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php

index f36a04a..45a7c02 100644 (file)
@@ -106,4 +106,11 @@ interface Horde_Kolab_Session
      * @return Horde_Kolab_Storage The storage connection.
      */
     public function getStorage();
+
+    /**
+     * Return the connection status of this session.
+     *
+     * @return boolean True if the session has been successfully connected.
+     */
+    public function isConnected();
 }
index 9c046a6..ef31e55 100644 (file)
@@ -179,4 +179,14 @@ class Horde_Kolab_Session_Anonymous implements Horde_Kolab_Session
     {
         return $this->_session->getStorage();
     }
+
+    /**
+     * Return the connection status of this session.
+     *
+     * @return boolean True if the session has been successfully connected.
+     */
+    public function isConnected()
+    {
+        return $this->_session->isConnected();
+    }
 }
index 8aa6e0d..a2ec455 100644 (file)
@@ -104,6 +104,13 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
     private $_storage;
 
     /**
+     * Indicate if this session was successfully connected.
+     *
+     * @var array
+     */
+    private $_connected = false;
+
+    /**
      * Constructor.
      *
      * @param string             $user_id The session will be setup for the user
@@ -154,6 +161,8 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
         $this->_initName($user_object);
         $this->_initImapServer($user_object);
         $this->_initFreebusyServer($user_object);
+
+        $this->_connected = true;
     }
 
     /**
@@ -354,6 +363,26 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session
      */
     public function getStorage()
     {
-        throw new Horde_Kolab_Session_Exception('Not implemented!');
+        if (empty($this->_storage)) {
+            //@todo: factory?
+            $this->_storage = new Horde_Kolab_Storage(
+                'Imap',
+                //@todo: Use Session_Auth
+                array('hostspec' => $this->getImapServer(),
+                      'username' => Horde_Auth::getAuth(),
+                      'password' => Horde_Auth::getCredential('password'))
+            );
+        }
+        return $this->_storage;
+    }
+
+    /**
+     * Return the connection status of this session.
+     *
+     * @return boolean True if the session has been successfully connected.
+     */
+    public function isConnected()
+    {
+        return $this->_connected;
     }
 }
index bba8424..d99dd32 100644 (file)
@@ -168,4 +168,14 @@ class Horde_Kolab_Session_Logged implements Horde_Kolab_Session
     {
         return $this->_session->getStorage();
     }
+
+    /**
+     * Return the connection status of this session.
+     *
+     * @return boolean True if the session has been successfully connected.
+     */
+    public function isConnected()
+    {
+        return $this->_session->isConnected();
+    }
 }
index 72d0654..033f70b 100644 (file)
@@ -60,7 +60,9 @@ class Horde_Kolab_Session_Singleton
             $config['logger']  = Horde::getLogger();
             $factory = new Horde_Kolab_Session_Factory_Configuration($config);
             self::$_instance = $factory->getSession($user);
-            self::$_instance->connect($credentials);
+            if (!self::$_instance->isConnected()) {
+                self::$_instance->connect($credentials);
+            }
         }
         return self::$_instance;
     }
index c145590..f73215e 100644 (file)
@@ -167,4 +167,14 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session
     {
         return $this->_session->getStorage();
     }
+
+    /**
+     * Return the connection status of this session.
+     *
+     * @return boolean True if the session has been successfully connected.
+     */
+    public function isConnected()
+    {
+        return $this->_session->isConnected();
+    }
 }