Horde/Share fixes.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 20 May 2010 16:50:28 +0000 (10:50 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 20 May 2010 17:06:17 +0000 (11:06 -0600)
There was no use of _instances in the factory - fix that.
Remove duplicate sessionobjects query.
Move sessionobjects caching entirely within factory, not main class.

framework/Core/lib/Horde/Core/Factory/Share.php
framework/Share/lib/Horde/Share.php

index 950c759..ecf3955 100644 (file)
@@ -65,34 +65,44 @@ class Horde_Core_Factory_Share
             $app = $this->_injector->getInstance('Horde_Registry')->getApp();
         }
 
-        $class = 'Horde_Share_' . ucfirst(basename($driver));
-        $signature = $app . '_' . $driver;
-        if (!isset($this->_instances[$signature]) &&
-            !empty($GLOBALS['conf']['share']['cache'])) {
+        $sig = $app . '_' . $driver;
 
-            $session = new Horde_SessionObjects();
-            $shares[$signature] = $session->query('horde_share_' . $app . '_' . $driver . '1');
+        if (isset($this->_instances[$sig])) {
+            return $this->_instances[$sig];
         }
 
-        if (empty($shares[$signature])) {
+        if (!empty($GLOBALS['conf']['share']['cache'])) {
+            $cache_sig = 'horde_share_' . $app . '_' . $driver . '1';
+            $ob = $this->_injector->getInstance('Horde_SessionObjects')->query($cache_sig);
+        }
+
+        if (empty($ob)) {
+            $class = 'Horde_Share_' . ucfirst(basename($driver));
             if (!class_exists($class)) {
-                throw new Horde_Exception((sprintf(_("\"%s\" share driver not found."), $driver)));
+                throw new Horde_Exception(sprintf(_("\"%s\" share driver not found."), $driver));
             }
 
-            $shares[$signature] = new $class($app, $this->_injector->getInstance('Horde_Perms'));
-        }
-
-        if (!isset($shares[$signature]) &&
-            !empty($GLOBALS['conf']['share']['cache'])) {
-            $session = new Horde_SessionObjects();
-            $shares[$signature] = $session->query('horde_share_' . $app . '_' . $driver . '1');
+            $ob = new $class($app, $this->_injector->getInstance('Horde_Perms'));
         }
 
         if (!empty($GLOBALS['conf']['share']['cache'])) {
-            register_shutdown_function(array($shares[$signature], 'shutdown'));
+            register_shutdown_function(array($this, 'shutdown'), $cache_sig, $ob);
         }
 
-        return $shares[$signature];
+        $this->_instances[$sig] = $ob;
+
+        return $ob;
+    }
+
+    /**
+     * Shutdown function.
+     *
+     * @param string $sig         Cache signature.
+     * @param Horde_Share $share  Horde_Share object to cache.
+     */
+    public function shutdown($sig, $share)
+    {
+        $this->_injector->getInstance('Horde_SessionObjects')->overwrite($sig, $share, false);
     }
 
 }
index 12215d2..3f9e75d 100644 (file)
@@ -116,16 +116,6 @@ class Horde_Share
     }
 
     /**
-     * Stores the object in the session cache.
-     */
-    public function shutdown()
-    {
-        $driver = str_replace('horde_share_', '', Horde_String::lower(get_class($this)));
-        $session = new Horde_SessionObjects();
-        $session->overwrite('horde_share_' . $this->_app . '_' . $driver, $this, false);
-    }
-
-    /**
      * Returns the application we're managing shares for.
      *
      * @return string  The application this share belongs to.