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-05-26 05:29:17 +00:00
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
|
|
|
* 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-05-26 05:29:17 +00:00
|
|
|
* @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
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +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
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $_objects = array();
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
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-05-26 05:29:17 +00:00
|
|
|
function &getInstance() {
|
|
|
|
static $instance = array();
|
|
|
|
if (!$instance) {
|
|
|
|
$instance[0] = &new ClassRegistry;
|
|
|
|
}
|
|
|
|
return $instance[0];
|
|
|
|
}
|
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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function addObject($key, &$object) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2006-05-26 05:29:17 +00:00
|
|
|
if (array_key_exists($key, $_this->_objects) === false) {
|
|
|
|
$_this->_objects[$key] = &$object;
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 00:11:40 +00:00
|
|
|
/**
|
|
|
|
* Remove object which corresponds to given key.
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @return void
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function removeObject($key) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2006-05-26 05:29:17 +00:00
|
|
|
if (array_key_exists($key, $_this->_objects) === true) {
|
|
|
|
unset($_this->_objects[$key]);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $key Key to look for
|
|
|
|
* @return boolean Success
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function isKeySet($key) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2006-05-26 05:29:17 +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
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function &getObject($key) {
|
|
|
|
$_this =& ClassRegistry::getInstance();
|
2006-11-27 01:04:19 +00:00
|
|
|
$key = Inflector::underscore($key);
|
2006-05-26 05:29:17 +00:00
|
|
|
return $_this->_objects[$key];
|
|
|
|
}
|
2005-09-17 02:22:07 +00:00
|
|
|
}
|
2005-08-21 06:49:02 +00:00
|
|
|
?>
|