mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-12 20:49:50 +00:00
Adding a normalize parameter to Object::_mergeVars(). This allows existing behavior to be maintained.
Updating Controller and Shell usage to match new parameters.
This commit is contained in:
parent
8821bec049
commit
8a129ec3a0
5 changed files with 22 additions and 29 deletions
|
@ -164,15 +164,13 @@ class Shell extends Object {
|
|||
if ($this->stdin == null) {
|
||||
$this->stdin = new ConsoleInput('php://stdin');
|
||||
}
|
||||
$merge = array();
|
||||
|
||||
$parent = get_parent_class($this);
|
||||
if ($this->tasks !== null && $this->tasks !== false) {
|
||||
$merge[] = 'tasks';
|
||||
$this->_mergeVars(array('tasks'), $parent, true);
|
||||
}
|
||||
if ($this->uses !== null && $this->uses !== false) {
|
||||
$merge[] = 'uses';
|
||||
}
|
||||
if (!empty($merge)) {
|
||||
$this->_mergeVars($merge, get_parent_class($this));
|
||||
$this->_mergeVars(array('uses'), $parent, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -441,31 +441,18 @@ class Controller extends Object {
|
|||
array_unshift($this->uses, $plugin . $this->modelClass);
|
||||
}
|
||||
} elseif ($this->uses !== null || $this->uses !== false) {
|
||||
$merge[] = 'uses';
|
||||
}
|
||||
|
||||
$this->_mergeVars($merge, 'AppController');
|
||||
foreach ($merge as $prop) {
|
||||
if ($prop !== 'components') {
|
||||
$this->{$prop} = array_unique((array)$this->{$prop});
|
||||
}
|
||||
$this->_mergeVars(array('uses'), 'AppController', false);
|
||||
}
|
||||
$this->_mergeVars($merge, 'AppController', true);
|
||||
}
|
||||
|
||||
if ($pluginController && $pluginName != null) {
|
||||
$appVars = get_class_vars($pluginController);
|
||||
$uses = $appVars['uses'];
|
||||
$merge = array('components', 'helpers');
|
||||
|
||||
if ($this->uses !== null || $this->uses !== false) {
|
||||
$merge[] = 'uses';
|
||||
$this->_mergeVars(array('uses'), $pluginController, false);
|
||||
}
|
||||
$this->_mergeVars($merge, $pluginController);
|
||||
foreach ($merge as $prop) {
|
||||
if ($prop !== 'components') {
|
||||
$this->{$prop} = array_unique((array)$this->{$prop});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -207,9 +207,10 @@ class Object {
|
|||
*
|
||||
* @param array $properties The name of the properties to merge.
|
||||
* @param sting $class The class to merge the property with.
|
||||
* @param boolean $normalize Set to true to run the properties through Set::normalize() before merging.
|
||||
* @return void
|
||||
*/
|
||||
protected function _mergeVars($properties, $class) {
|
||||
protected function _mergeVars($properties, $class, $normalize = true) {
|
||||
$classProperties = get_class_vars($class);
|
||||
foreach ($properties as $var) {
|
||||
if (
|
||||
|
@ -218,6 +219,10 @@ class Object {
|
|||
is_array($this->{$var}) &&
|
||||
$this->{$var} != $classProperties[$var]
|
||||
) {
|
||||
if ($normalize) {
|
||||
$classProperties[$var] = Set::normalize($classProperties[$var]);
|
||||
$this->{$var} = Set::normalize($this->{$var});
|
||||
}
|
||||
$this->{$var} = Set::merge($classProperties[$var], $this->{$var});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,8 @@ class TestShell extends Shell {
|
|||
|
||||
}
|
||||
|
||||
public function mergeVars($properties, $class) {
|
||||
return $this->_mergeVars($properties, $class);
|
||||
public function mergeVars($properties, $class, $normalize = true) {
|
||||
return $this->_mergeVars($properties, $class, $normalize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,9 +156,12 @@ class ShellTest extends CakeTestCase {
|
|||
function testMergeVars() {
|
||||
$this->Shell->tasks = array('DbConfig' => array('one', 'two'));
|
||||
$this->Shell->uses = array('Posts');
|
||||
$this->Shell->mergeVars(array('tasks', 'uses'), 'TestMergeShell');
|
||||
$this->Shell->mergeVars(array('tasks'), 'TestMergeShell');
|
||||
$this->Shell->mergeVars(array('uses'), 'TestMergeShell', false);
|
||||
|
||||
$expected = array('DbConfig' => null, 'Fixture' => null, 'DbConfig' => array('one', 'two'));
|
||||
$this->assertEquals($expected, $this->Shell->tasks);
|
||||
|
||||
$this->assertEquals(array('DbConfig', 'Fixture', 'DbConfig' => array('one', 'two')), $this->Shell->tasks);
|
||||
$expected = array('Fixture' => null, 'DbConfig' => array('one', 'two'));
|
||||
$this->assertEquals($expected, Set::normalize($this->Shell->tasks), 'Normalized results are wrong.');
|
||||
$this->assertEquals(array('Comment', 'Posts'), $this->Shell->uses, 'Merged models are wrong.');
|
||||
|
|
|
@ -201,7 +201,7 @@ class ControllerMergeVarsTest extends CakeTestCase {
|
|||
'Custom' => null,
|
||||
'Foo' => array('something')
|
||||
);
|
||||
$this->assertIdentical($Controller->helpers, $expected, 'Order is incorrect. %s');
|
||||
$this->assertSame($Controller->helpers, $expected, 'Order is incorrect.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,7 +239,7 @@ class ControllerMergeVarsTest extends CakeTestCase {
|
|||
'MergeVar' => array('flag', 'otherFlag', 'redirect' => false),
|
||||
'Auth' => array('setting' => 'val', 'otherVal'),
|
||||
);
|
||||
$this->assertEqual($expected, $Controller->components, 'Components are unexpected.');
|
||||
$this->assertEquals($expected, $Controller->components, 'Components are unexpected.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue