diff --git a/cake/libs/configure.php b/cake/libs/configure.php index c38462b51eb..d77a8e98772 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -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); } } @@ -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. @@ -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. @@ -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() @@ -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,