2005-08-21 06:49:02 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Class collections.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* A repository for class objects, each registered with a key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2005-12-23 21:57:26 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @filesource
|
2006-01-20 07:46:14 +00:00
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
* @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.
|
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* A repository for class objects, each registered with a key.
|
2005-09-17 02:22:07 +00:00
|
|
|
* 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.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
* @since CakePHP v 0.9.2
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
class ClassRegistry
|
|
|
|
{
|
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Names of classes with their objects.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @var array
|
2005-08-21 06:49:02 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
var $_objects = array();
|
|
|
|
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Return a singleton instance of the ClassRegistry.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* @return ClassRegistry instance
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function &getInstance()
|
|
|
|
{
|
2005-08-21 06:49:02 +00:00
|
|
|
static $instance = array();
|
|
|
|
if (!$instance)
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$instance[0] =& new ClassRegistry;
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
|
|
|
return $instance[0];
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Add $object to the registry, associating it with the name $key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-01-12 02:10:47 +00:00
|
|
|
* @param string $key
|
2005-09-17 02:22:07 +00:00
|
|
|
* @param mixed $object
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
|
|
|
function addObject($key, &$object)
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$_this =& ClassRegistry::getInstance();
|
2005-08-21 06:49:02 +00:00
|
|
|
$key = strtolower($key);
|
2006-01-12 02:10:47 +00:00
|
|
|
|
|
|
|
if (array_key_exists($key, $_this->_objects) === false)
|
2005-08-21 06:49:02 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$_this->_objects[$key] =& $object;
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Returns true if given key is present in the ClassRegistry.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @param string $key Key to look for
|
|
|
|
* @return boolean Success
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
|
|
|
function isKeySet($key)
|
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
$_this =& ClassRegistry::getInstance();
|
2005-08-21 06:49:02 +00:00
|
|
|
$key = strtolower($key);
|
2006-01-12 02:10:47 +00:00
|
|
|
return array_key_exists($key, $_this->_objects);
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Return object which corresponds to given key.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @param string $key
|
|
|
|
* @return mixed
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
|
|
|
function &getObject($key)
|
|
|
|
{
|
|
|
|
$key = strtolower($key);
|
2006-01-12 02:10:47 +00:00
|
|
|
$_this =& ClassRegistry::getInstance();
|
|
|
|
return $_this->_objects[$key];
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
2005-08-21 06:49:02 +00:00
|
|
|
?>
|