Skip to content

Commit

Permalink
Optimizing and simplifying Configure::write(), this also allows arbit…
Browse files Browse the repository at this point in the history
…rary nesting limit in configure keys
  • Loading branch information
lorenzo committed Jan 14, 2012
1 parent 2c5cb11 commit 3a48f64
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions lib/Cake/Core/Configure.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -124,26 +124,12 @@ public static function write($config, $value = null) {
} }


foreach ($config as $name => $value) { foreach ($config as $name => $value) {
if (strpos($name, '.') === false) { $pointer = &self::$_values;
self::$_values[$name] = $value; foreach (explode('.', $name) as $key) {
} else { $pointer = &$pointer[$key];
$names = explode('.', $name, 4);
switch (count($names)) {
case 2:
self::$_values[$names[0]][$names[1]] = $value;
break;
case 3:
self::$_values[$names[0]][$names[1]][$names[2]] = $value;
break;
case 4:
$names = explode('.', $name, 2);
if (!isset(self::$_values[$names[0]])) {
self::$_values[$names[0]] = array();
}
self::$_values[$names[0]] = Set::insert(self::$_values[$names[0]], $names[1], $value);
break;
}
} }
$pointer = $value;
unset($pointer);
} }


if (isset($config['debug']) && function_exists('ini_set')) { if (isset($config['debug']) && function_exists('ini_set')) {
Expand Down

0 comments on commit 3a48f64

Please sign in to comment.