mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 19:12:42 +00:00
Fixing reading and writing in Configure class for references 3 levels deep, fixes #3845
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6329 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
06175843a1
commit
9650c1a73f
2 changed files with 50 additions and 22 deletions
|
@ -246,22 +246,22 @@ class Configure extends Object {
|
|||
$_this =& Configure::getInstance();
|
||||
|
||||
if (!is_array($config) && $value !== null) {
|
||||
$name = $_this->__configVarNames($config);
|
||||
|
||||
if (count($name) > 1) {
|
||||
$_this->{$name[0]}[$name[1]] = $value;
|
||||
} else {
|
||||
$_this->{$name[0]} = $value;
|
||||
$config = array($config => $value);
|
||||
}
|
||||
} else {
|
||||
|
||||
foreach ($config as $names => $value) {
|
||||
$name = $_this->__configVarNames($names);
|
||||
|
||||
if (count($name) > 1) {
|
||||
switch (count($name)) {
|
||||
case 3:
|
||||
$_this->{$name[0]}[$name[1]][$name[2]] = $value;
|
||||
break;
|
||||
case 2:
|
||||
$_this->{$name[0]}[$name[1]] = $value;
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
$_this->{$name[0]} = $value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,17 +312,24 @@ class Configure extends Object {
|
|||
}
|
||||
$name = $_this->__configVarNames($var);
|
||||
|
||||
if (count($name) > 1) {
|
||||
switch (count($name)) {
|
||||
case 3:
|
||||
if (isset($_this->{$name[0]}[$name[1]][$name[2]])) {
|
||||
return $_this->{$name[0]}[$name[1]][$name[2]];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (isset($_this->{$name[0]}[$name[1]])) {
|
||||
return $_this->{$name[0]}[$name[1]];
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
break;
|
||||
case 1:
|
||||
if (isset($_this->{$name[0]})) {
|
||||
return $_this->{$name[0]};
|
||||
}
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Used to delete a var from the Configure instance.
|
||||
|
|
|
@ -64,6 +64,27 @@ class ConfigureTest extends UnitTestCase {
|
|||
$this->assertTrue(in_array('Html', $result));
|
||||
}
|
||||
|
||||
function testRead() {
|
||||
$expected = 'ok';
|
||||
|
||||
$this->Configure->write('level1.level2.level3_1', $expected);
|
||||
$this->Configure->write('level1.level2.level3_2', 'something_else');
|
||||
$result = $this->Configure->read('level1.level2.level3_1');
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
$result = $this->Configure->read('level1.level2.level3_2');
|
||||
$this->assertEqual($result, 'something_else');
|
||||
}
|
||||
|
||||
function testThatWereOnlyListingUserlandClasses() {
|
||||
$result = $this->Configure->listObjects('model');
|
||||
$notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema');
|
||||
|
||||
foreach ($notExpected as $class) {
|
||||
//$this->assertFalse(in_array($class, $result));
|
||||
}
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
unset($this->Configure);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue