From 9a909c553fe361620ba5440619a39fd7fd8cca06 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 24 Jul 2009 13:50:50 -0700 Subject: [PATCH] updating configure to handle infinite depths of keys. thanks to farhadi. --- cake/libs/configure.php | 81 ++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 53 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index c38462b51..d77a8e987 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -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,