mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
fixes #5307, model name being overridden by class registry for no reason, thanks to vizjerai for the helpful ticket.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7501 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
4b3a5f5df0
commit
e35a215883
4 changed files with 32 additions and 31 deletions
|
@ -106,49 +106,45 @@ class ClassRegistry {
|
|||
$objects = array(array('class' => $class));
|
||||
}
|
||||
|
||||
$defaults = array_merge(
|
||||
array('id' => false, 'table' => null, 'ds' => null, 'alias' => null, 'name' => null),
|
||||
isset($_this->__config[$type]) ? $_this->__config[$type] : array()
|
||||
);
|
||||
$defaults = isset($_this->__config[$type]) ? $_this->__config[$type] : array();
|
||||
|
||||
$count = count($objects);
|
||||
foreach ($objects as $key => $settings) {
|
||||
if (is_array($settings)) {
|
||||
$plugin = null;
|
||||
$settings = array_merge($defaults, $settings);
|
||||
extract($settings, EXTR_OVERWRITE);
|
||||
|
||||
$class = $settings['class'];
|
||||
if (strpos($class, '.') !== false) {
|
||||
list($plugin, $class) = explode('.', $class);
|
||||
$plugin = $plugin . '.';
|
||||
}
|
||||
|
||||
if (empty($alias)) {
|
||||
$alias = $class;
|
||||
if (empty($settings['alias'])) {
|
||||
$settings['alias'] = $class;
|
||||
}
|
||||
$alias = $settings['alias'];
|
||||
|
||||
if ($model =& $_this->_duplicate($alias, $class)) {
|
||||
$_this->map($alias, $class);
|
||||
return $model;
|
||||
}
|
||||
|
||||
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);
|
||||
${$class} =& new $class($settings);
|
||||
} elseif ($type === 'Model') {
|
||||
if ($plugin && class_exists($plugin .'AppModel')) {
|
||||
$appModel = $plugin .'AppModel';
|
||||
} else {
|
||||
$appModel = 'AppModel';
|
||||
}
|
||||
${$class} =& new $appModel($options);
|
||||
${$class} =& new $appModel(array_merge($settings, array('name' => $class)));
|
||||
}
|
||||
|
||||
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;
|
||||
die();
|
||||
}
|
||||
|
||||
if ($type !== 'Model') {
|
||||
|
|
|
@ -315,7 +315,9 @@ class Model extends Overloadable {
|
|||
parent::__construct();
|
||||
|
||||
if (is_array($id)) {
|
||||
extract(array_merge(array('id' => false, 'table' => null, 'ds' => null, 'name' => null, 'alias' => null), $id));
|
||||
extract(array_merge(
|
||||
array('id' => $this->id, 'table' => $this->useTable, 'ds' => $this->useDbConfig, 'name' => $this->name, 'alias' => $this->alias),
|
||||
$id));
|
||||
$this->name = $name;
|
||||
$this->alias = $alias;
|
||||
}
|
||||
|
@ -331,6 +333,7 @@ class Model extends Overloadable {
|
|||
if ($this->primaryKey === null) {
|
||||
$this->primaryKey = 'id';
|
||||
}
|
||||
|
||||
ClassRegistry::addObject($this->alias, $this);
|
||||
|
||||
$this->id = $id;
|
||||
|
|
|
@ -29,14 +29,14 @@
|
|||
App::import('Core', 'ClassRegistry');
|
||||
/**
|
||||
* ClassRegisterModel class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class ClassRegisterModel extends CakeTestModel {
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
|
@ -44,14 +44,14 @@ class ClassRegisterModel extends CakeTestModel {
|
|||
}
|
||||
/**
|
||||
* RegisterArticle class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class RegisterArticle extends ClassRegisterModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
*
|
||||
* @var string 'RegisterArticle'
|
||||
* @access public
|
||||
*/
|
||||
|
@ -59,14 +59,14 @@ class RegisterArticle extends ClassRegisterModel {
|
|||
}
|
||||
/**
|
||||
* RegisterArticleFeatured class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class RegisterArticleFeatured extends ClassRegisterModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
*
|
||||
* @var string 'RegisterArticlFeatured'
|
||||
* @access public
|
||||
*/
|
||||
|
@ -74,14 +74,14 @@ class RegisterArticleFeatured extends ClassRegisterModel {
|
|||
}
|
||||
/**
|
||||
* RegisterArticleTag class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class RegisterArticleTag extends ClassRegisterModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
*
|
||||
* @var string 'RegisterArticlTag'
|
||||
* @access public
|
||||
*/
|
||||
|
@ -89,14 +89,14 @@ class RegisterArticleTag extends ClassRegisterModel {
|
|||
}
|
||||
/**
|
||||
* RegistryPluginAppModel class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class RegistryPluginAppModel extends ClassRegisterModel {
|
||||
/**
|
||||
* tablePrefix property
|
||||
*
|
||||
*
|
||||
* @var string 'something_'
|
||||
* @access public
|
||||
*/
|
||||
|
@ -104,14 +104,14 @@ class RegistryPluginAppModel extends ClassRegisterModel {
|
|||
}
|
||||
/**
|
||||
* TestRegistryPluginModel class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class TestRegistryPluginModel extends RegistryPluginAppModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
*
|
||||
* @var string 'TestRegistryPluginModel'
|
||||
* @access public
|
||||
*/
|
||||
|
@ -119,14 +119,14 @@ class TestRegistryPluginModel extends RegistryPluginAppModel {
|
|||
}
|
||||
/**
|
||||
* ClassRegistryTest class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class ClassRegistryTest extends CakeTestCase {
|
||||
/**
|
||||
* testAddModel method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -167,7 +167,7 @@ class ClassRegistryTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testClassRegistryFlush method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -182,7 +182,7 @@ class ClassRegistryTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testAddMultiplModels method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -223,7 +223,7 @@ class ClassRegistryTest extends CakeTestCase {
|
|||
}
|
||||
/**
|
||||
* testPluginAppModel method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
|
|
@ -104,7 +104,7 @@ class ControllerComment extends CakeTestModel {
|
|||
* @var string 'ControllerComment'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'ControllerComment';
|
||||
var $name = 'Comment';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
|
@ -253,6 +253,8 @@ class ControllerTest extends CakeTestCase {
|
|||
$Controller->constructClasses();
|
||||
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
||||
$this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment'));
|
||||
|
||||
$this->assertEqual($Controller->ControllerComment->name, 'Comment');
|
||||
|
||||
unset($Controller);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue