Permalink
Browse files

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

  • Loading branch information...
1 parent 7f6c2b6 commit 9a909c553fe361620ba5440619a39fd7fd8cca06 gwoo committed Jul 24, 2009
Showing with 28 additions and 53 deletions.
  1. +28 −53 cake/libs/configure.php
View
@@ -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.
@@ -333,22 +324,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,

0 comments on commit 9a909c5

Please sign in to comment.