Navigation Menu

Skip to content

Commit

Permalink
updating configure to handle infinite depths of keys. thanks to farhadi.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwoo committed Jul 24, 2009
1 parent 7f6c2b6 commit 9a909c5
Showing 1 changed file with 28 additions and 53 deletions.
81 changes: 28 additions & 53 deletions cake/libs/configure.php
Expand Up @@ -92,19 +92,15 @@ function write($config, $value = null) {
$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);
}
}

Expand Down Expand Up @@ -154,26 +150,20 @@ function read($var = 'debug') {
}
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.
Expand All @@ -189,13 +179,14 @@ function read($var = 'debug') {
*/
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.
Expand Down Expand Up @@ -332,22 +323,6 @@ function __writeConfig($content, $name, $write = true) {
}
}
}
/**
* 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()
Expand Down Expand Up @@ -412,7 +387,7 @@ function __loadBootstrap($boot) {
} 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,
Expand Down

0 comments on commit 9a909c5

Please sign in to comment.