mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Closes #5560 Class Registry::_duplicate call for getObject returns false it will cause an error
Added additional optimizations. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7734 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
2f85fefa29
commit
aa248a126f
1 changed files with 16 additions and 22 deletions
|
@ -94,9 +94,9 @@ class ClassRegistry {
|
||||||
function &init($class, $type = null) {
|
function &init($class, $type = null) {
|
||||||
$_this =& ClassRegistry::getInstance();
|
$_this =& ClassRegistry::getInstance();
|
||||||
$id = $false = false;
|
$id = $false = false;
|
||||||
$table = $ds = $alias = $plugin = null;
|
$table = $ds = $alias = $plugin = $options = null;
|
||||||
$options = null;
|
|
||||||
$true = true;
|
$true = true;
|
||||||
|
|
||||||
if (!$type) {
|
if (!$type) {
|
||||||
$type = 'Model';
|
$type = 'Model';
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,9 @@ class ClassRegistry {
|
||||||
} else {
|
} else {
|
||||||
$objects = array(array('class' => $class));
|
$objects = array(array('class' => $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaults = isset($_this->__config[$type]) ? $_this->__config[$type] : array();
|
$defaults = isset($_this->__config[$type]) ? $_this->__config[$type] : array();
|
||||||
|
|
||||||
$count = count($objects);
|
$count = count($objects);
|
||||||
|
|
||||||
foreach ($objects as $key => $settings) {
|
foreach ($objects as $key => $settings) {
|
||||||
if (is_array($settings)) {
|
if (is_array($settings)) {
|
||||||
$plugin = $pluginPath = null;
|
$plugin = $pluginPath = null;
|
||||||
|
@ -129,7 +128,7 @@ class ClassRegistry {
|
||||||
}
|
}
|
||||||
$alias = $settings['alias'];
|
$alias = $settings['alias'];
|
||||||
|
|
||||||
if ($model =& $_this->_duplicate($alias, $class)) {
|
if ($model =& $_this->__duplicate($alias, $class)) {
|
||||||
$_this->map($alias, $class);
|
$_this->map($alias, $class);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +164,6 @@ class ClassRegistry {
|
||||||
if ($count > 1) {
|
if ($count > 1) {
|
||||||
return $true;
|
return $true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ${$class};
|
return ${$class};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -180,7 +178,7 @@ class ClassRegistry {
|
||||||
function addObject($key, &$object) {
|
function addObject($key, &$object) {
|
||||||
$_this =& ClassRegistry::getInstance();
|
$_this =& ClassRegistry::getInstance();
|
||||||
$key = Inflector::underscore($key);
|
$key = Inflector::underscore($key);
|
||||||
if (array_key_exists($key, $_this->__objects) === false) {
|
if (!isset($_this->__objects[$key])) {
|
||||||
$_this->__objects[$key] =& $object;
|
$_this->__objects[$key] =& $object;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +195,7 @@ class ClassRegistry {
|
||||||
function removeObject($key) {
|
function removeObject($key) {
|
||||||
$_this =& ClassRegistry::getInstance();
|
$_this =& ClassRegistry::getInstance();
|
||||||
$key = Inflector::underscore($key);
|
$key = Inflector::underscore($key);
|
||||||
if (array_key_exists($key, $_this->__objects) === true) {
|
if (isset($_this->__objects[$key])) {
|
||||||
unset($_this->__objects[$key]);
|
unset($_this->__objects[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,9 +210,9 @@ class ClassRegistry {
|
||||||
function isKeySet($key) {
|
function isKeySet($key) {
|
||||||
$_this =& ClassRegistry::getInstance();
|
$_this =& ClassRegistry::getInstance();
|
||||||
$key = Inflector::underscore($key);
|
$key = Inflector::underscore($key);
|
||||||
if (array_key_exists($key, $_this->__objects)) {
|
if (isset($_this->__objects[$key])) {
|
||||||
return true;
|
return true;
|
||||||
} elseif (array_key_exists($key, $_this->__map)) {
|
} elseif (isset($_this->__map[$key])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -250,7 +248,6 @@ class ClassRegistry {
|
||||||
$return =& $_this->__objects[$key];
|
$return =& $_this->__objects[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -275,7 +272,6 @@ class ClassRegistry {
|
||||||
} elseif (empty($param) && is_string($type)) {
|
} elseif (empty($param) && is_string($type)) {
|
||||||
return isset($_this->__config[$type]) ? $_this->__config[$type] : null;
|
return isset($_this->__config[$type]) ? $_this->__config[$type] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$_this->__config[$type] = $param;
|
$_this->__config[$type] = $param;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -284,15 +280,14 @@ class ClassRegistry {
|
||||||
* @param string $alias
|
* @param string $alias
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @access protected
|
* @access private
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function &_duplicate($alias, $class) {
|
function &__duplicate($alias, $class) {
|
||||||
$_this =& ClassRegistry::getInstance();
|
|
||||||
$duplicate = false;
|
$duplicate = false;
|
||||||
if ($_this->isKeySet($alias)) {
|
if ($this->isKeySet($alias)) {
|
||||||
$model =& $_this->getObject($alias);
|
$model =& $this->getObject($alias);
|
||||||
if (is_a($model, $class) || $model->alias === $class) {
|
if (is_object($model) && (is_a($model, $class) || $model->alias === $class)) {
|
||||||
$duplicate =& $model;
|
$duplicate =& $model;
|
||||||
}
|
}
|
||||||
unset($model);
|
unset($model);
|
||||||
|
@ -311,7 +306,7 @@ class ClassRegistry {
|
||||||
$_this =& ClassRegistry::getInstance();
|
$_this =& ClassRegistry::getInstance();
|
||||||
$key = Inflector::underscore($key);
|
$key = Inflector::underscore($key);
|
||||||
$name = Inflector::underscore($name);
|
$name = Inflector::underscore($name);
|
||||||
if (array_key_exists($key, $_this->__map) === false) {
|
if (!isset($_this->__map[$key])) {
|
||||||
$_this->__map[$key] = $name;
|
$_this->__map[$key] = $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,9 +330,8 @@ class ClassRegistry {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function __getMap($key) {
|
function __getMap($key) {
|
||||||
$_this =& ClassRegistry::getInstance();
|
if (isset($this->__map[$key])) {
|
||||||
if (array_key_exists($key, $_this->__map)) {
|
return $this->__map[$key];
|
||||||
return $_this->__map[$key];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue