Changeset 2527

Show
Ignore:
Timestamp:
04/17/2008 03:14:37 PM (7 months ago)
Author:
JAAulde
Message:

merged trunk r2526 in to releases/2.1.2

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • releases/2.1.2/system/libraries/Database.php

    r2166 r2527  
    7474                        $config = Config::item('database.default'); 
    7575                } 
     76                elseif (is_array($config) && count($config) > 0) 
     77                { 
     78                        if ( ! array_key_exists('connection', $config)) 
     79                        { 
     80                                $config = array('connection' => $config); 
     81                        } 
     82                } 
    7683                elseif (is_string($config)) 
    7784                { 
     
    95102                $this->config = array_merge($this->config, $config); 
    96103 
    97                 // Make sure the connection is valid 
    98                 if (strpos($this->config['connection'], '://') === FALSE) 
    99                         throw new Kohana_Database_Exception('database.invalid_dsn', $this->config['connection']); 
    100  
    101                 // Parse the DSN, creating an array to hold the connection parameters 
    102                 $db = array 
    103                 ( 
    104                         'type'     => FALSE, 
    105                         'user'     => FALSE, 
    106                         'pass'     => FALSE, 
    107                         'host'     => FALSE, 
    108                         'port'     => FALSE, 
    109                         'socket'   => FALSE, 
    110                         'database' => FALSE 
    111                 ); 
    112  
    113                 // Get the protocol and arguments 
    114                 list ($db['type'], $connection) = explode('://', $this->config['connection'], 2); 
    115  
    116                 if (strpos($connection, '@') !== FALSE) 
    117                 { 
    118                         // Get the username and password 
    119                         list ($db['pass'], $connection) = explode('@', $connection, 2); 
    120                         // Check if a password is supplied 
    121                         $logindata = explode(':', $db['pass'], 2); 
    122                         $db['pass'] = (count($logindata) > 1) ? $logindata[1] : ''; 
    123                         $db['user'] = $logindata[0]; 
    124  
    125                         // Prepare for finding the database 
    126                         $connection = explode('/', $connection); 
    127  
    128                         // Find the database name 
    129                         $db['database'] = array_pop($connection); 
    130  
    131                         // Reset connection string 
    132                         $connection = implode('/', $connection); 
    133  
    134                         // Find the socket 
    135                         if (preg_match('/^unix\([^)]++\)/', $connection)) 
     104                if (is_string($this->config['connection'])) 
     105                { 
     106                        // Make sure the connection is valid 
     107                        if (strpos($this->config['connection'], '://') === FALSE) 
     108                                throw new Kohana_Database_Exception('database.invalid_dsn', $this->config['connection']); 
     109 
     110                        // Parse the DSN, creating an array to hold the connection parameters 
     111                        $db = array 
     112                        ( 
     113                                'type'     => FALSE, 
     114                                'user'     => FALSE, 
     115                                'pass'     => FALSE, 
     116                                'host'     => FALSE, 
     117                                'port'     => FALSE, 
     118                                'socket'   => FALSE, 
     119                                'database' => FALSE 
     120                        ); 
     121 
     122                        // Get the protocol and arguments 
     123                        list ($db['type'], $connection) = explode('://', $this->config['connection'], 2); 
     124 
     125                        if (strpos($connection, '@') !== FALSE) 
    136126                        { 
    137                                 // This one is a little hairy: we explode based on the end of 
    138                                 // the socket, removing the 'unix(' from the connection string 
    139                                 list ($db['socket'], $connection) = explode(')', substr($connection, 5), 2); 
    140                         } 
    141                         elseif (strpos($connection, ':') !== FALSE) 
    142                         { 
    143                                 // Fetch the host and port name 
    144                                 list ($db['host'], $db['port']) = explode(':', $connection, 2); 
     127                                // Get the username and password 
     128                                list ($db['pass'], $connection) = explode('@', $connection, 2); 
     129                                // Check if a password is supplied 
     130                                $logindata = explode(':', $db['pass'], 2); 
     131                                $db['pass'] = (count($logindata) > 1) ? $logindata[1] : ''; 
     132                                $db['user'] = $logindata[0]; 
     133 
     134                                // Prepare for finding the database 
     135                                $connection = explode('/', $connection); 
     136 
     137                                // Find the database name 
     138                                $db['database'] = array_pop($connection); 
     139 
     140                                // Reset connection string 
     141                                $connection = implode('/', $connection); 
     142 
     143                                // Find the socket 
     144                                if (preg_match('/^unix\([^)]++\)/', $connection)) 
     145                                { 
     146                                        // This one is a little hairy: we explode based on the end of 
     147                                        // the socket, removing the 'unix(' from the connection string 
     148                                        list ($db['socket'], $connection) = explode(')', substr($connection, 5), 2); 
     149                                } 
     150                                elseif (strpos($connection, ':') !== FALSE) 
     151                                { 
     152                                        // Fetch the host and port name 
     153                                        list ($db['host'], $db['port']) = explode(':', $connection, 2); 
     154                                } 
     155                                else 
     156                                { 
     157                                        $db['host'] = $connection; 
     158                                } 
    145159                        } 
    146160                        else 
    147161                        { 
    148                                 $db['host'] = $connection; 
     162                                // File connection 
     163                                $connection = explode('/', $connection); 
     164 
     165                                // Find database file name 
     166                                $db['database'] = array_pop($connection); 
     167 
     168                                // Find database directory name 
     169                                $db['socket'] = implode('/', $connection).'/'; 
    149170                        } 
    150                 } 
    151                 else 
    152                 { 
    153                         // File connection 
    154                         $connection = explode('/', $connection); 
    155  
    156                         // Find database file name 
    157                         $db['database'] = array_pop($connection); 
    158  
    159                         // Find database directory name 
    160                         $db['socket'] = implode('/', $connection).'/'; 
    161                 } 
    162  
    163                 // Reset the connection array to the database config 
    164                 $this->config['connection'] = $db; 
    165  
     171 
     172                        // Reset the connection array to the database config 
     173                        $this->config['connection'] = $db; 
     174                } 
    166175                // Set driver name 
    167176                $driver = 'Database_'.ucfirst($this->config['connection']['type']).'_Driver';