rename to _normalizeConfig, since we normalize horde names to pdo as well as rails...
authorChuck Hagenbuch <chuck@horde.org>
Fri, 20 Feb 2009 04:22:23 +0000 (23:22 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Fri, 20 Feb 2009 04:22:23 +0000 (23:22 -0500)
framework/Db/lib/Horde/Db/Adapter/Pdo/Abstract.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Mysql.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Sqlite.php

index 948690f..46723cf 100644 (file)
@@ -178,11 +178,11 @@ abstract class Horde_Db_Adapter_Pdo_Abstract extends Horde_Db_Adapter_Abstract
         }
     }
 
-    protected function _railsToPdo($params)
+    protected function _normalizeConfig($params)
     {
-        // rewrite rails config key names to pdo equivalents
-        $rails2pdo = array('database' => 'dbname', 'socket' => 'unix_socket', 'hostspec' => 'host');
-        foreach ($rails2pdo as $from => $to) {
+        // normalize config parameters to what PDO expects
+        $normalize = array('database' => 'dbname', 'socket' => 'unix_socket', 'hostspec' => 'host');
+        foreach ($normalize as $from => $to) {
             if (isset($params[$from])) {
                 $params[$to] = $params[$from];
                 unset($params[$from]);
@@ -194,14 +194,11 @@ abstract class Horde_Db_Adapter_Pdo_Abstract extends Horde_Db_Adapter_Abstract
 
     protected function _buildDsnString($params)
     {
-         // build DSN string
         $dsn = $this->_config['adapter'] . ':';
         foreach ($params as $k => $v) {
             $dsn .= "$k=$v;";
         }
-        $dsn = rtrim($dsn, ';');
-
-        return $dsn;
+        return rtrim($dsn, ';');
     }
 
     /**
@@ -217,14 +214,10 @@ abstract class Horde_Db_Adapter_Pdo_Abstract extends Horde_Db_Adapter_Abstract
         // collect options to build PDO Data Source Name (DSN) string
         $dsnOpts = $this->_config;
         unset($dsnOpts['adapter'], $dsnOpts['username'], $dsnOpts['password']);
-        $dsnOpts = $this->_railsToPdo($dsnOpts);
-
-        // build DSN string
-        $dsn = $this->_buildDsnString($dsnOpts);
 
         // return DSN and user/pass for connection
         return array(
-            $dsn,
+            $this->_buildDsnString($this->_normalizeConfig($dsnOpts)),
             $this->_config['username'],
             $this->_config['password']);
     }
index fbfc4ac..b193411 100644 (file)
@@ -88,7 +88,7 @@ class Horde_Db_Adapter_Pdo_Mysql extends Horde_Db_Adapter_Pdo_Abstract
         // collect options to build PDO Data Source Name (DSN) string
         $dsnOpts = $this->_config;
         unset($dsnOpts['adapter'], $dsnOpts['username'], $dsnOpts['password']);
-        $dsnOpts = $this->_railsToPdo($dsnOpts);
+        $dsnOpts = $this->_normalizeConfig($dsnOpts);
 
         if (isset($dsnOpts['port'])) {
             if (empty($dsnOpts['host'])) {
@@ -102,11 +102,9 @@ class Horde_Db_Adapter_Pdo_Mysql extends Horde_Db_Adapter_Pdo_Abstract
             }
         }
 
-        $dsn = $this->_buildDsnString($dsnOpts);
-
         // return DSN and user/pass for connection
         return array(
-            $dsn,
+            $this->_buildDsnString($dsnOpts),
             $this->_config['username'],
             $this->_config['password']);
     }
index d03fa44..bae89f4 100644 (file)
@@ -170,8 +170,13 @@ class Horde_Db_Adapter_Pdo_Sqlite extends Horde_Db_Adapter_Pdo_Abstract
         }
     }
 
+    protected function _buildDsnString($params)
+    {
+        return 'sqlite:' . $params['dbname'];
+    }
+
     /**
-     * Parse YAML configuration array into options for PDO constructor
+     * Parse configuration array into options for PDO constructor
      *
      * @throws  Horde_Db_Exception
      * @return  array  [dsn, username, password]
@@ -187,13 +192,9 @@ class Horde_Db_Adapter_Pdo_Sqlite extends Horde_Db_Adapter_Pdo_Abstract
         // collect options to build PDO Data Source Name (DSN) string
         $dsnOpts = $this->_config;
         unset($dsnOpts['adapter'], $dsnOpts['username'], $dsnOpts['password']);
-        $dsnOpts = $this->_railsToPdo($dsnOpts);
-
-        // build DSN string
-        $dsn = 'sqlite:' . $dsnOpts['dbname'];
 
         // return DSN and dummy user/pass for connection
-        return array($dsn, '', '');
+        return array($this->_buildDsnString($this->_normalizeConfig($dsnOpts)), '', '');
     }
 
 }