2006-01-12 02:10:47 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2006-01-20 07:46:14 +00:00
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
2006-01-12 02:10:47 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2006-01-20 07:46:14 +00:00
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
2006-01-12 02:10:47 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.model
|
|
|
|
* @since CakePHP v 0.10.x.1402
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages loaded instances of DataSource objects
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.model
|
|
|
|
* @since CakePHP v 0.10.x.1402
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
uses('model'.DS.'datasources'.DS.'datasource');
|
|
|
|
class ConnectionManager extends Object
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds a loaded instance of the Connections object
|
|
|
|
*
|
|
|
|
* @var class:Connections
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $config = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds instances DataSource objects
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
var $_dataSources = array();
|
|
|
|
|
2006-01-17 17:52:23 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
if(class_exists('DATABASE_CONFIG'))
|
|
|
|
{
|
|
|
|
$this->config = new DATABASE_CONFIG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a reference to the ConnectionManger object instance
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
function &getInstance()
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
static $instance = array();
|
|
|
|
if(!isset($instance[0]) || !$instance[0])
|
2006-01-12 02:10:47 +00:00
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
$instance[0] =& new ConnectionManager();
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
2006-02-17 10:12:15 +00:00
|
|
|
return $instance[0];
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a reference to a DataSource object
|
|
|
|
*
|
|
|
|
* @param string $name The name of the DataSource, as defined in app/config/connections
|
|
|
|
* @return object
|
|
|
|
*/
|
|
|
|
function &getDataSource($name)
|
|
|
|
{
|
|
|
|
$_this =& ConnectionManager::getInstance();
|
|
|
|
|
|
|
|
if(in_array($name, array_keys($_this->_dataSources)))
|
|
|
|
{
|
|
|
|
return $_this->_dataSources[$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(in_array($name, array_keys(get_object_vars($_this->config))))
|
|
|
|
{
|
|
|
|
$config = $_this->config->{$name};
|
|
|
|
|
|
|
|
if(isset($config['driver']) && $config['driver'] != null && $config['driver'] != '')
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
$filename = 'dbo_'.$config['driver'];
|
|
|
|
$classname = Inflector::camelize(strtolower('DBO_'.$config['driver']));
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
$filename = $config['datasource'].'_source';
|
|
|
|
$classname = Inflector::camelize(strtolower($config['datasource'].'_source'));
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$tail = 'dbo'.DS.$filename.'.php';
|
2006-02-17 10:12:15 +00:00
|
|
|
if(!class_exists($classname))
|
2006-01-12 02:10:47 +00:00
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
if (fileExistsInPath(LIBS.'model'.DS.$tail))
|
|
|
|
{
|
|
|
|
require(LIBS.'model'.DS.$tail);
|
|
|
|
}
|
|
|
|
else if (file_exists(MODELS.$tail))
|
|
|
|
{
|
|
|
|
require(MODELS.$tail);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trigger_error('Unable to load model file ' . $filename . '.php', E_USER_ERROR);
|
|
|
|
return null;
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
}
|
|
|
|
$_this->_dataSources[$name] =& new $classname($config);
|
|
|
|
$_this->_dataSources[$name]->configKeyName = $name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trigger_error("ConnectionManager::getDataSource - Non-existent data source {$name}", E_USER_ERROR);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $_this->_dataSources[$name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|