updating configure to handle infinite depths of keys. thanks to farhadi.

This commit is contained in:
gwoo 2009-07-24 13:50:50 -07:00
parent 7f6c2b6b33
commit 9a909c553f

View file

@ -92,19 +92,15 @@ class Configure extends Object {
$config = array($config => $value);
}
foreach ($config as $names => $value) {
$name = $_this->__configVarNames($names);
switch (count($name)) {
case 3:
$_this->{$name[0]}[$name[1]][$name[2]] = $value;
break;
case 2:
$_this->{$name[0]}[$name[1]] = $value;
break;
case 1:
$_this->{$name[0]} = $value;
break;
foreach ($config as $name => $value) {
if (strpos($name, '.') === false) {
$_this->{$name} = $value;
} else {
$names = explode('.', $name, 2);
if (!isset($_this->{$names[0]})) {
$_this->{$names[0]} = array();
}
$_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
}
}
@ -154,26 +150,20 @@ class Configure extends Object {
}
return $_this->debug;
}
$name = $_this->__configVarNames($var);
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]];
}
break;
case 1:
if (isset($_this->{$name[0]})) {
return $_this->{$name[0]};
}
break;
if (strpos($var, '.') !== false) {
$names = explode('.', $var, 2);
$var = $names[0];
}
return null;
if (!isset($_this->{$var})) {
return null;
}
if (!empty($names[1])) {
return Set::extract($_this->{$var}, $names[1]);
}
return $_this->{$var};
}
/**
* Used to delete a variable from the Configure instance.
@ -189,13 +179,14 @@ class Configure extends Object {
*/
function delete($var = null) {
$_this =& Configure::getInstance();
$name = $_this->__configVarNames($var);
if (count($name) > 1) {
unset($_this->{$name[0]}[$name[1]]);
} else {
unset($_this->{$name[0]});
if (strpos($var, '.') === false) {
unset($_this->{$var});
return;
}
$names = explode('.', $var, 2);
$_this->{$names[0]} = Set::remove($_this->{$names[0]}, $names[1]);
}
/**
* Loads a file from app/config/configure_file.php.
@ -332,22 +323,6 @@ class Configure extends Object {
}
}
}
/**
* Checks $name for dot notation to create dynamic Configure::$var as an array when needed.
*
* @param mixed $name Name to split
* @return array Name separated in items through dot notation
* @access private
*/
function __configVarNames($name) {
if (is_string($name)) {
if (strpos($name, ".")) {
return explode(".", $name);
}
return array($name);
}
return $name;
}
/**
* @deprecated
* @see App::objects()
@ -412,7 +387,7 @@ class Configure extends Object {
} else {
$duration = '+999 days';
}
if (Cache::config('_cake_core_') === false) {
Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,