cakephp2-php8/cake/libs/model/connection_manager.php

145 lines
3.4 KiB
PHP
Raw Normal View History

Merging changes to trunk: Revision: [1761] Removing old db_acl.sql Revision: [1759] Removed unneeded calls to uses(). Changed basics.php listClasses() no longer using folder class. Starting corrections in DboPostgres class. Adding missing DboPostgres::query(). Added missing doc blocks to AjaxHelper. Fixed undefined keys in FormHelper::generateFields() Reformatted FormHelper::generateFields() adding open and close brackets where needed Revision: [1758] Fixed typo Revision: [1757] Fixed errors found when using PHP 4. Fixed a scaffold error Revision: [1756] Merging changes to model_php4.php Revision: [1755] Fixed scaffolding for the changes made to the model. Fixed Model::isForeignKey(), replaced array_key_exists with in_array, other function was failing Revision: [1754] Committing changes from bundt model to beta. DataSources will not be in the beta release Revision: [1751] Cleaning up a little more in the code. Removing loading of log.php unless it is really needed. Refactored dispatcher to speed up the stripslashes code if it is called Revision: [1748] removing all references to error_messages and deleting the file Revision: [1747] updated more error messages Revision: [1746] removing all error message defines Revision: [1745] added _() method from 1.0 to basics.php only used to return string right now Revision: [1744] Adding fix for ticket #220 Revision: [1743] More work on ErrorHandler class Revision: [1742] Renaming error view for missing database connection Revision: [1741] More work on ErrorHandler class Revision: [1740] More work on error class Revision: [1739] Replacing all $_SERVER variable check with env() in basics.php Revision: [1738] Adding env() to basic Revision: [1737] Updated session to use env() Revision: [1736] Removing ternary operators from Dispatcher Revision: [1735] Per nates request I am rolling back ACL to [1373] Revision: [1734] Removed the IP in the session class this was not very reliable. Added a time setting that generates current time adding the Security::inactiveMins() to the session Removed code that was added to basics.php to replace gethostbyaddr(). Added CAKE_SESSION_STRING define to core.php which is used in the by the Session class to generate a hashed key. Revision: [1733] Moving errors messages to ErrorHandler class. Updating errors view for use with new class. Updating Scaffold to use new class. Updated Dispatcher to use new class. Removing methods from Object class Revision: [1732] Adding ErrorHandler class Revision: [1731] Adding fix for Ticket #223 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1762 3807eeeb-6ff5-0310-8944-8be069107fe0
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/>
* Copyright (c) 2005, Cake Software Foundation, Inc.
* 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
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @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();
/**
* Constructor.
*
*/
function __construct()
{
if(class_exists('DATABASE_CONFIG'))
{
$this->config = new DATABASE_CONFIG();
}
}
/**
* Gets a reference to the ConnectionManger object instance
*
* @return object
*/
function &getInstance()
{
static $instance = null;
if($instance == null)
{
$instance =& new ConnectionManager();
}
return $instance;
}
/**
* 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'] != '')
{
$filename = 'dbo_'.$config['driver'];
$classname = Inflector::camelize(strtolower('DBO_'.$config['driver']));
}
else
{
$filename = $config['datasource'].'_source';
$classname = Inflector::camelize(strtolower($config['datasource'].'_source'));
}
$tail = 'dbo'.DS.$filename.'.php';
if (file_exists(LIBS.'model'.DS.$tail))
{
require_once(LIBS.'model'.DS.$tail);
}
else if (file_exists(MODELS.$tail))
{
require_once(MODELS.$tail);
}
else
{
trigger_error('Unable to load model file ' . $filename . '.php', E_USER_ERROR);
return null;
}
$_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];
}
}
?>