refactored class regsitry init

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6199 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-12-22 19:25:24 +00:00
parent 0a703ef8c0
commit eed0f6c570

View file

@ -91,92 +91,65 @@ class ClassRegistry {
}
if (is_array($class)) {
if (isset($class[0])) {
foreach ($class as $key => $setttings) {
if (is_array($setttings)) {
$plugin = null;
$objects = $class;
if (!isset($class[0])) {
$objects = array($class);
}
} else {
$objects = array(array('class' => $class));
}
extract($setttings, EXTR_OVERWRITE);
$count = count($objects);
foreach ($objects as $key => $settings) {
if (is_array($settings)) {
$plugin = null;
$settings = array_merge(array('id' => false, 'table' => null, 'ds' => null, 'alias' => null, 'name' => null), $settings);
extract($settings, EXTR_OVERWRITE);
if (strpos($class, '.') !== false) {
list($plugin, $class) = explode('.', $class);
$plugin = $plugin . '.';
}
if (empty($alias)) {
$alias = $class;
}
if ($_this->_duplicate($alias, $class) && $count == 1) {
$_this->map($alias, $class);
return $_this->getObject($alias);
}
if ($type === 'Model') {
$options = array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias, 'name' => $class);
}
if (App::import($type, $plugin . $class)) {
${$class} = new $class($options);
if($type !== 'Model') {
$_this->addObject($this->alias, ${$class});
} else {
$_this->map($alias, $class);
} elseif ($type === 'Model') {
${$class} = new AppModel($options);
}
} else {
if (!isset(${$class})) {
trigger_error(sprintf(__('(ClassRegistry::init() could not create instance of %1$s class %2$s ', true), $class, $type), E_USER_WARNING);
return $false;
}
} elseif (is_numeric($setttings)) {
if ($type !== 'Model') {
$_this->addObject($this->alias, ${$class});
} else {
$_this->map($alias, $class);
}
} elseif (is_numeric($settings)) {
trigger_error(__('(ClassRegistry::init() Attempted to create instance of a class with a numeric name', true), E_USER_WARNING);
return $false;
}
}
if ($count > 1) {
return $true;
} else {
extract($class, EXTR_OVERWRITE);
if (strpos($class, '.') !== false) {
list($plugin, $class) = explode('.', $class);
$plugin = $plugin . '.';
}
if ($_this->_duplicate($alias, $class)) {
$_this->map($alias, $class);
return $_this->getObject($alias);
}
if ($type === 'Model') {
$options = array('id' => $id, 'table' => $table, 'ds' => $ds, 'alias' => $alias, 'name' => $class);
}
if (App::import($type, $plugin . $class)) {
${$class} = new $class($options);
if($type !== 'Model') {
$_this->addObject($this->alias, ${$class});
} else {
$_this->map($alias, $class);
}
} else {
return $false;
}
}
} else {
if (strpos($class, '.') !== false) {
list($plugin, $class) = explode('.', $class);
$plugin = $plugin . '.';
}
$alias = $class;
if ($_this->_duplicate($alias, $class)) {
$_this->map($alias, $class);
return $_this->getObject($alias);
}
if ($type === 'Model') {
$option = array('name' => $class, 'alias' => $alias, 'id' => $id);
}
if (App::import($type, $plugin . $class)) {
${$class} = new $class($option);
if($type !== 'Model') {
$_this->addObject($this->alias, ${$class});
} else {
$_this->map($alias, $class);
}
} else {
return $false;
}
}
return ${$class};
}
/**