diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index b09eda5c462..d1e3c20eca9 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -62,6 +62,7 @@ function __construct() { if (class_exists('DATABASE_CONFIG')) { $this->config =& new DATABASE_CONFIG(); } + $this->_getConnectionObjects(); } /** @@ -96,14 +97,13 @@ function &getDataSource($name) { $return =& $_this->_dataSources[$name]; 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); $null = null; return $null; } - $conn = $connections[$name]; + $conn = $_this->_connectionsEnum[$name]; $class = $conn['classname']; if ($_this->loadDataSource($name) === null) { @@ -165,8 +165,7 @@ function loadDataSource($connName) { if (is_array($connName)) { $conn = $connName; } else { - $connections = $_this->enumConnectionObjects(); - $conn = $connections[$connName]; + $conn = $_this->_connectionsEnum[$connName]; } if (class_exists($conn['classname'])) { @@ -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 * (as defined in Connections), and the value is an array with keys 'filename' and 'classname'. @@ -198,19 +197,7 @@ function loadDataSource($connName) { function enumConnectionObjects() { $_this =& ConnectionManager::getInstance(); - if (!empty($_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'))); - } + return $_this->_connectionsEnum; } /** @@ -235,6 +222,25 @@ function &create($name = '', $config = array()) { 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. *