Move Horde_Db_Adapter binder to a factory, change factory method to create()
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 7 Oct 2010 15:58:14 +0000 (11:58 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 7 Oct 2010 15:58:14 +0000 (11:58 -0400)
framework/Core/lib/Horde/Core/Binder/DbBase.php [deleted file]
framework/Core/lib/Horde/Core/Factory/Db.php
framework/Core/lib/Horde/Core/Factory/DbBase.php [new file with mode: 0644]
framework/Core/lib/Horde/Core/Factory/Group.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml

diff --git a/framework/Core/lib/Horde/Core/Binder/DbBase.php b/framework/Core/lib/Horde/Core/Binder/DbBase.php
deleted file mode 100644 (file)
index d3afda6..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/**
- * @category Horde
- * @package  Core
- */
-class Horde_Core_Binder_DbBase implements Horde_Injector_Binder
-{
-    /**
-     * Returns the Horde_Db_Adapter object for the default Horde DB/SQL
-     * configuration.
-     *
-     * @return Horde_Db_Adapter
-     * @throws Horde_Exception
-     */
-    public function create(Horde_Injector $injector)
-    {
-        $db = new Horde_Core_Factory_Db($injector);
-        return $db->getDb('horde');
-    }
-
-    public function equals(Horde_Injector_Binder $binder)
-    {
-        return false;
-    }
-
-}
index 538bf06..79c0ea6 100644 (file)
@@ -81,7 +81,7 @@ class Horde_Core_Factory_Db
         /* Determine if we are using the base SQL config. */
         if (isset($config['driverconfig']) &&
             ($config['driverconfig'] == 'horde')) {
-            $this->_instances[$sig] = $this->getDb();
+            $this->_instances[$sig] = $this->create();
             return $this->_instances[$sig];
         }
 
diff --git a/framework/Core/lib/Horde/Core/Factory/DbBase.php b/framework/Core/lib/Horde/Core/Factory/DbBase.php
new file mode 100644 (file)
index 0000000..4b74a67
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+/**
+ * @category Horde
+ * @package  Core
+ */
+class Horde_Core_Factory_DbBase
+{
+    /**
+     * Returns the Horde_Db_Adapter object for the default Horde DB/SQL
+     * configuration.
+     *
+     * @return Horde_Db_Adapter
+     * @throws Horde_Exception
+     */
+    public function create(Horde_Injector $injector)
+    {
+        return $injector->getInstance('Horde_Core_Factory_Db')->create('horde');
+    }
+
+}
diff --git a/framework/Core/lib/Horde/Core/Factory/Group.php b/framework/Core/lib/Horde/Core/Factory/Group.php
new file mode 100644 (file)
index 0000000..51cf271
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+/**
+ * @category Horde
+ * @package  Core
+ */
+class Horde_Core_Factory_Group implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        $group = null;
+        if (!empty($GLOBALS['conf']['group']['cache'])) {
+            $session = new Horde_SessionObjects();
+            $group = $session->query('horde_group');
+        }
+
+        if (!$group) {
+            $driver = $GLOBALS['conf']['group']['driver'];
+            $params = Horde::getDriverConfig('group', $driver);
+            if ($driver == 'ldap') {
+                $params['ldap'] = $injector->getInstance('Horde_Core_Factory_Ldap')->getLdap('horde', 'group');
+            }
+            $group = Horde_Group::factory($driver, $params);
+        }
+
+        if (!empty($GLOBALS['conf']['group']['cache'])) {
+            register_shutdown_function(array($group, 'shutdown'));
+        }
+
+        return $group;
+    }
+
+}
index 4a8fe21..a7c24e8 100644 (file)
@@ -265,7 +265,6 @@ class Horde_Registry
         $binders = array(
             'Horde_Auth_Factory' => new Horde_Core_Binder_AuthFactory(),
             'Horde_Core_Auth_Signup' => new Horde_Core_Binder_AuthSignup(),
-            'Horde_Db_Adapter' => new Horde_Core_Binder_DbBase(),
             'Horde_Db_Pear' => new Horde_Core_Binder_DbPear(),
             'Horde_History' => new Horde_Core_Binder_History(),
             'Horde_Http_Client' => new Horde_Core_Binder_HttpClient(),
@@ -302,6 +301,10 @@ class Horde_Registry
                 'Horde_Core_Controller_RequestMapper',
                 'getRequestConfiguration',
             ),
+            'Horde_Db_Adapter' => array(
+                'Horde_Core_Factory_DbBase',
+                'create',
+            ),
             'Horde_Editor' => array(
                 'Horde_Core_Factory_Editor',
                 'create',
index b4511bf..2ffe26f 100644 (file)
@@ -113,7 +113,6 @@ Application Framework.</description>
        <file name="Auth.php" role="php" />
        <file name="AuthFactory.php" role="php" />
        <file name="AuthSignup.php" role="php" />
-       <file name="DbBase.php" role="php" />
        <file name="DbPear.php" role="php" />
        <file name="Group.php" role="php" />
        <file name="History.php" role="php" />
@@ -143,6 +142,7 @@ Application Framework.</description>
        <file name="Crypt.php" role="php" />
        <file name="Data.php" role="php" />
        <file name="Db.php" role="php" />
+       <file name="DbBase.php" role="php" />
        <file name="DbPear.php" role="php" />
        <file name="Dns.php" role="php" />
        <file name="Editor.php" role="php" />
@@ -428,7 +428,6 @@ Application Framework.</description>
    <install as="Horde/Core/Binder/Auth.php" name="lib/Horde/Core/Binder/Auth.php" />
    <install as="Horde/Core/Binder/AuthFactory.php" name="lib/Horde/Core/Binder/AuthFactory.php" />
    <install as="Horde/Core/Binder/AuthSignup.php" name="lib/Horde/Core/Binder/AuthSignup.php" />
-   <install as="Horde/Core/Binder/DbBase.php" name="lib/Horde/Core/Binder/DbBase.php" />
    <install as="Horde/Core/Binder/DbPear.php" name="lib/Horde/Core/Binder/DbPear.php" />
    <install as="Horde/Core/Binder/Group.php" name="lib/Horde/Core/Binder/Group.php" />
    <install as="Horde/Core/Binder/History.php" name="lib/Horde/Core/Binder/History.php" />
@@ -454,6 +453,7 @@ Application Framework.</description>
    <install as="Horde/Core/Factory/Crypt.php" name="lib/Horde/Core/Factory/Crypt.php" />
    <install as="Horde/Core/Factory/Data.php" name="lib/Horde/Core/Factory/Data.php" />
    <install as="Horde/Core/Factory/Db.php" name="lib/Horde/Core/Factory/Db.php" />
+   <install as="Horde/Core/Factory/DbBase.php" name="lib/Horde/Core/Factory/DbBase.php" />
    <install as="Horde/Core/Factory/DbPear.php" name="lib/Horde/Core/Factory/DbPear.php" />
    <install as="Horde/Core/Factory/Dns.php" name="lib/Horde/Core/Factory/Dns.php" />
    <install as="Horde/Core/Factory/Editor.php" name="lib/Horde/Core/Factory/Editor.php" />