Skip to content

Commit

Permalink
Getting a list of connections in the constructor of ConnectionManager
Browse files Browse the repository at this point in the history
class. Fixes issues where using ConnectionManager::create() before the
standard connections are enumerated will result in the standard
connections never being enumerated.  Fixes #206

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information
jrbasso authored and markstory committed Jan 21, 2010
1 parent 2915493 commit b21538c
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions cake/libs/model/connection_manager.php
Expand Up @@ -62,6 +62,7 @@ function __construct() {
if (class_exists('DATABASE_CONFIG')) { if (class_exists('DATABASE_CONFIG')) {
$this->config =& new DATABASE_CONFIG(); $this->config =& new DATABASE_CONFIG();
} }
$this->_getConnectionObjects();
} }


/** /**
Expand Down Expand Up @@ -96,14 +97,13 @@ function &getDataSource($name) {
$return =& $_this->_dataSources[$name]; $return =& $_this->_dataSources[$name];
return $return; return $return;
} }
$connections = $_this->enumConnectionObjects();


if (empty($connections[$name])) { if (empty($_this->_connectionsEnum[$name])) {
trigger_error(sprintf(__("ConnectionManager::getDataSource - Non-existent data source %s", true), $name), E_USER_ERROR); trigger_error(sprintf(__("ConnectionManager::getDataSource - Non-existent data source %s", true), $name), E_USER_ERROR);
$null = null; $null = null;
return $null; return $null;
} }
$conn = $connections[$name]; $conn = $_this->_connectionsEnum[$name];
$class = $conn['classname']; $class = $conn['classname'];


if ($_this->loadDataSource($name) === null) { if ($_this->loadDataSource($name) === null) {
Expand Down Expand Up @@ -165,8 +165,7 @@ function loadDataSource($connName) {
if (is_array($connName)) { if (is_array($connName)) {
$conn = $connName; $conn = $connName;
} else { } else {
$connections = $_this->enumConnectionObjects(); $conn = $_this->_connectionsEnum[$connName];
$conn = $connections[$connName];
} }


if (class_exists($conn['classname'])) { if (class_exists($conn['classname'])) {
Expand All @@ -188,7 +187,7 @@ function loadDataSource($connName) {
} }


/** /**
* Gets a list of class and file names associated with the user-defined DataSource connections * Return a list of connections
* *
* @return array An associative array of elements where the key is the connection name * @return array An associative array of elements where the key is the connection name
* (as defined in Connections), and the value is an array with keys 'filename' and 'classname'. * (as defined in Connections), and the value is an array with keys 'filename' and 'classname'.
Expand All @@ -198,19 +197,7 @@ function loadDataSource($connName) {
function enumConnectionObjects() { function enumConnectionObjects() {
$_this =& ConnectionManager::getInstance(); $_this =& ConnectionManager::getInstance();


if (!empty($_this->_connectionsEnum)) { return $_this->_connectionsEnum;
return $_this->_connectionsEnum;
}
$connections = get_object_vars($_this->config);

if ($connections != null) {
foreach ($connections as $name => $config) {
$_this->_connectionsEnum[$name] = $_this->__connectionData($config);
}
return $_this->_connectionsEnum;
} else {
$_this->cakeError('missingConnection', array(array('className' => 'ConnectionManager')));
}
} }


/** /**
Expand All @@ -235,6 +222,25 @@ function &create($name = '', $config = array()) {
return $return; return $return;
} }


/**
* Gets a list of class and file names associated with the user-defined DataSource connections
*
* @return void
* @access protected
* @static
*/
function _getConnectionObjects() {
$connections = get_object_vars($this->config);

if ($connections != null) {
foreach ($connections as $name => $config) {
$this->_connectionsEnum[$name] = $this->__connectionData($config);
}
} else {
$this->cakeError('missingConnection', array(array('className' => 'ConnectionManager')));
}
}

/** /**
* Returns the file, class name, and parent for the given driver. * Returns the file, class name, and parent for the given driver.
* *
Expand Down

0 comments on commit b21538c

Please sign in to comment.