mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Reverting changes to Behavior so that all models use the same behavior instance, fixes #6038, refs #4408.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8087 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
55e72bb749
commit
4466c9f7b7
3 changed files with 35 additions and 11 deletions
|
@ -273,13 +273,23 @@ class BehaviorCollection extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->{$name})) {
|
if (!isset($this->{$name})) {
|
||||||
if (PHP5) {
|
if (ClassRegistry::isKeySet($class)) {
|
||||||
$this->{$name} = new $class;
|
if (PHP5) {
|
||||||
|
$this->{$name} = ClassRegistry::getObject($class);
|
||||||
|
} else {
|
||||||
|
$this->{$name} =& ClassRegistry::getObject($class);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->{$name} =& new $class;
|
if (PHP5) {
|
||||||
|
$this->{$name} = new $class;
|
||||||
|
} else {
|
||||||
|
$this->{$name} =& new $class;
|
||||||
|
}
|
||||||
|
ClassRegistry::addObject($class, $this->{$name});
|
||||||
}
|
}
|
||||||
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) {
|
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) {
|
||||||
if (!empty($config)) {
|
if ($config !== null && $config !== false) {
|
||||||
|
// if (!empty($config)) {
|
||||||
$config = array_merge($this->{$name}->settings[$this->modelName], $config);
|
$config = array_merge($this->{$name}->settings[$this->modelName], $config);
|
||||||
} else {
|
} else {
|
||||||
$config = array();
|
$config = array();
|
||||||
|
@ -295,11 +305,18 @@ class BehaviorCollection extends Object {
|
||||||
}
|
}
|
||||||
$methods = get_class_methods($this->{$name});
|
$methods = get_class_methods($this->{$name});
|
||||||
$parentMethods = array_flip(get_class_methods('ModelBehavior'));
|
$parentMethods = array_flip(get_class_methods('ModelBehavior'));
|
||||||
$callbacks = array('setup' => true, 'cleanup' => true, 'beforeFind' => true, 'afterFind' => true, 'beforeSave' => true, 'afterSave' => true, 'beforeDelete' => true, 'afterDelete' => true, 'afterError' => true);
|
$callbacks = array(
|
||||||
|
'setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave',
|
||||||
|
'beforeDelete', 'afterDelete', 'afterError'
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($methods as $m) {
|
foreach ($methods as $m) {
|
||||||
if (!isset($parentMethods[$m])) {
|
if (!isset($parentMethods[$m])) {
|
||||||
if ($m[0] != '_' && !array_key_exists($m, $this->__methods) && !isset($callbacks[$m])) {
|
$methodAllowed = (
|
||||||
|
$m[0] != '_' && !array_key_exists($m, $this->__methods) &&
|
||||||
|
!in_array($m, $callbacks)
|
||||||
|
);
|
||||||
|
if ($methodAllowed) {
|
||||||
$this->__methods[$m] = array($m, $name);
|
$this->__methods[$m] = array($m, $name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,8 +375,11 @@ class BehaviorTest extends CakeTestCase {
|
||||||
$this->assertIdentical($Apple->Sample->Behaviors->attached(), array('Test'));
|
$this->assertIdentical($Apple->Sample->Behaviors->attached(), array('Test'));
|
||||||
$this->assertEqual($Apple->Sample->Behaviors->Test->settings['Sample'], array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2'));
|
$this->assertEqual($Apple->Sample->Behaviors->Test->settings['Sample'], array('beforeFind' => 'on', 'afterFind' => 'off', 'key2' => 'value2'));
|
||||||
|
|
||||||
$this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple'));
|
$this->assertEqual(array_keys($Apple->Behaviors->Test->settings), array('Apple', 'Sample'));
|
||||||
$this->assertEqual(array_keys($Apple->Sample->Behaviors->Test->settings), array('Sample'));
|
$this->assertIdentical(
|
||||||
|
$Apple->Sample->Behaviors->Test->settings,
|
||||||
|
$Apple->Behaviors->Test->settings
|
||||||
|
);
|
||||||
$this->assertNotIdentical($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
$this->assertNotIdentical($Apple->Behaviors->Test->settings['Apple'], $Apple->Sample->Behaviors->Test->settings['Sample']);
|
||||||
|
|
||||||
$Apple->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
$Apple->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'beforeFind' => 'off'));
|
||||||
|
@ -398,14 +401,20 @@ class BehaviorTest extends CakeTestCase {
|
||||||
$this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior'));
|
$this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior'));
|
||||||
|
|
||||||
$Apple->Behaviors->attach('Plugin.Test', array('key' => 'new value'));
|
$Apple->Behaviors->attach('Plugin.Test', array('key' => 'new value'));
|
||||||
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], array('beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value', 'key2' => 'value2', 'key3' => 'value3'));
|
$expected = array(
|
||||||
|
'beforeFind' => 'off', 'afterFind' => 'off', 'key' => 'new value',
|
||||||
|
'key2' => 'value2', 'key3' => 'value3'
|
||||||
|
);
|
||||||
|
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
|
||||||
|
|
||||||
$current = $Apple->Behaviors->Test->settings['Apple'];
|
$current = $Apple->Behaviors->Test->settings['Apple'];
|
||||||
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
|
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
|
||||||
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
|
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
|
||||||
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
|
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
|
||||||
|
|
||||||
$Apple->Behaviors->attach('Test');
|
$Apple->Behaviors->attach('Test');
|
||||||
$expected = array_merge($current, array('mangle' => 'trigger mangled mangled'));
|
$expected = array_merge($current, array('mangle' => 'trigger mangled mangled'));
|
||||||
|
|
||||||
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
|
$this->assertEqual($Apple->Behaviors->Test->settings['Apple'], $expected);
|
||||||
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
|
$Apple->Behaviors->attach('Test', array('mangle' => 'trigger'));
|
||||||
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
|
$expected = array_merge($current, array('mangle' => 'trigger mangled'));
|
||||||
|
|
|
@ -1571,8 +1571,6 @@ class ModelTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testUpdateWithCalculation() {
|
function testUpdateWithCalculation() {
|
||||||
Configure::write('foo', true);
|
|
||||||
|
|
||||||
$this->loadFixtures('DataTest');
|
$this->loadFixtures('DataTest');
|
||||||
$model =& new DataTest();
|
$model =& new DataTest();
|
||||||
$result = $model->saveAll(array(
|
$result = $model->saveAll(array(
|
||||||
|
|
Loading…
Reference in a new issue