Permalink
Browse files

Optimizing Configure::delete(), you can now delete arbitrarily nested…

… keys
  • Loading branch information...
1 parent eab2d8a commit 81b41aa561d8aa0ccf58ed1a130bcb575d72bb6a @lorenzo lorenzo committed Jan 15, 2012
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/Cake/Core/Configure.php
@@ -188,13 +188,13 @@ public static function read($var = null) {
* @return void
*/
public static function delete($var = null) {
- if (strpos($var, '.') === false) {
- unset(self::$_values[$var]);
- return;
+ $keys = explode('.', $var);
+ $last = array_pop($keys);
+ $pointer = &self::$_values;
+ foreach ($keys as $key) {
+ $pointer = &$pointer[$key];
}
-
- $names = explode('.', $var, 2);
- self::$_values[$names[0]] = Set::remove(self::$_values[$names[0]], $names[1]);
+ unset($pointer[$last]);
}
/**

0 comments on commit 81b41aa

Please sign in to comment.