cakephp2-php8/cake/libs/class_registry.php
phpnut 73830ec0dc Merging fixes and enhancements into trunk
Revision: [1841]
Merging changes made in model_php5.php to model_php4.php

Revision: [1840]
Adding fix for PHP 5 when using mysql_connect setting.
Commented out the call to Dbo*::disconnect(). This was closing connections early.
Adding fixe for Ticket #302.
Adding Enhancement for Ticket #300.
Adding fix for Ticket #299
Adding Enhancement for Ticket #298
Adding fix for Ticket #297
Adding Enhancement/Patch from Ticket #296

Revision: [1838]
working on deeper recursive joins

Revision: [1837]
Updating copyright information in all files

Revision: [1836]
Adding fix when setting a field value to 0.
Before it would set this to NULL, which was not expected result.  


git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1842 3807eeeb-6ff5-0310-8944-8be069107fe0
2006-01-20 07:46:14 +00:00

111 lines
No EOL
2.6 KiB
PHP

<?php
/* SVN FILE: $Id$ */
/**
* Class collections.
*
* A repository for class objects, each registered with a key.
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2006, 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) 2006, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP v 0.9.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Class Collections.
*
* A repository for class objects, each registered with a key.
* If you try to add an object with the same key twice, nothing will come of it.
* If you need a second instance of an object, give it another key.
*
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP v 0.9.2
*/
class ClassRegistry
{
/**
* Names of classes with their objects.
*
* @var array
* @access private
*/
var $_objects = array();
/**
* Return a singleton instance of the ClassRegistry.
*
* @return ClassRegistry instance
*/
function &getInstance()
{
static $instance = array();
if (!$instance)
{
$instance[0] =& new ClassRegistry;
}
return $instance[0];
}
/**
* Add $object to the registry, associating it with the name $key.
*
* @param string $key
* @param mixed $object
*/
function addObject($key, &$object)
{
$_this =& ClassRegistry::getInstance();
$key = strtolower($key);
if (array_key_exists($key, $_this->_objects) === false)
{
$_this->_objects[$key] =& $object;
}
}
/**
* Returns true if given key is present in the ClassRegistry.
*
* @param string $key Key to look for
* @return boolean Success
*/
function isKeySet($key)
{
$_this =& ClassRegistry::getInstance();
$key = strtolower($key);
return array_key_exists($key, $_this->_objects);
}
/**
* Return object which corresponds to given key.
*
* @param string $key
* @return mixed
*/
function &getObject($key)
{
$key = strtolower($key);
$_this =& ClassRegistry::getInstance();
return $_this->_objects[$key];
}
}
?>