CVS update: /cowiki/includes/cowiki/class/dao/

[email protected] 12 Apr 2005 18:42:08 -0000
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
User: dgorski 
Date: 05/04/12 11:42:08

Modified:
 /cowiki/includes/cowiki/class/dao/
  class.StorageFactory.php

Log:
 Manufacure the right storage abstraction for users and documents.
 Possible schemas: mysql, mysqli, mysql+innodb, mysqli+innodb

File Changes:

Directory: /cowiki/includes/cowiki/class/dao/
=============================================

File [changed]: class.StorageFactory.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/dao/class.StorageFactory.php?r1=1.10&r2=1.11
Delta lines:  +43 -10
---------------------
--- class.StorageFactory.php	16 Jan 2005 23:20:50 -0000	1.10
+++ class.StorageFactory.php	12 Apr 2005 18:42:08 -0000	1.11
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.StorageFactory.php,v 1.10 2005/01/16 23:20:50 dgorski Exp $
+ * $Id: class.StorageFactory.php,v 1.11 2005/04/12 18:42:08 dgorski Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -17,7 +17,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.10 $
+ * @version     $Revision: 1.11 $
  *
  */
 
@@ -38,6 +38,8 @@
     protected static
         $Instance = null;
 
+    // --------------------------------------------------------------------
+
     /**
      * Get instance
      *
@@ -57,6 +59,8 @@
         return self::$Instance;
     }
 
+    // --------------------------------------------------------------------
+
     /**
      * Create doc storage
      *
@@ -70,6 +74,8 @@
      */
     protected function __construct() {}
 
+    // --------------------------------------------------------------------
+
     /**
      * Create doc storage
      *
@@ -84,9 +90,11 @@
      */
     public function createDocStorage() {
         $Registry = RuntimeContext::getInstance()->getRegistry();
-        return $this->_create($Registry->get('.DOCUMENT_RESOURCE'), 550, 551);
+        return $this->create($Registry->get('.DOCUMENT_RESOURCE'), 550, 551);
     }
 
+    // --------------------------------------------------------------------
+
     /**
      * Create user storage
      *
@@ -101,11 +109,13 @@
      */
     public function createUserStorage() {
         $Registry = RuntimeContext::getInstance()->getRegistry();
-        return $this->_create($Registry->get('.USER_RESOURCE'), 554, 555);
+        return $this->create($Registry->get('.USER_RESOURCE'), 554, 555);
     }
 
+    // --------------------------------------------------------------------
+
     /**
-     * _create
+     * create
      *
      * @access  protected
      * @param   string
@@ -122,9 +132,11 @@
      * @todo    [D11N]  Check return type
      * @todo    [FIX]   think about resource-recycling here
      */
-    protected function _create($sResource, $nApiErr, $nConnErr) {
+    protected function create($sResource, $nApiErr, $nConnErr) {
         $UriInfo = new UriInfo($sResource);
-        if ($UriInfo->get('scheme') == 'mysql') {
+        $sScheme = $UriInfo->get('scheme');
+
+        if ($sScheme == 'mysql' || $sScheme == 'mysql+innodb') {
 
             // FIX: think about resource-recycling here
 
@@ -140,9 +152,7 @@
                 $UriInfo->get('basepath')
             );
 
-            if ($bSuccess) {
-                return $Storage;
-            }
+            if ($bSuccess) { return $Storage; }
 
             // Connect failed
             RuntimeContext::getInstance()->addError($nConnErr);
@@ -150,6 +160,29 @@
         }
 
         // ---
+
+        if ($sScheme == 'mysqli' || $sScheme == 'mysqli+innodb') {
+
+            // FIX: think about resource-recycling here
+
+            // New abstraction layer
+            $Storage = new StorageMySQLi();
+
+            // Connect service
+            $bSuccess = $Storage->connect(
+                $UriInfo->get('host'),
+                $UriInfo->get('port'),
+                $UriInfo->get('user'),
+                $UriInfo->get('pass'),
+                $UriInfo->get('basepath')
+            );
+
+            if ($bSuccess) { return $Storage; }
+
+            // Connect failed
+            RuntimeContext::getInstance()->addError($nConnErr);
+            RuntimeContext::getInstance()->terminate();
+        }
 
         // Unknown storage API
         RuntimeContext::getInstance()->addError($nApiErr);