Skip to content

Commit

Permalink
Optimizing Configure::read(), now it is possible to read arbitrarily …
Browse files Browse the repository at this point in the history
…nested keys
  • Loading branch information
lorenzo committed Jan 15, 2012
1 parent 3a48f64 commit eab2d8a
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions lib/Cake/Core/Configure.php
Expand Up @@ -163,30 +163,15 @@ public static function read($var = null) {
if (isset(self::$_values[$var])) {
return self::$_values[$var];
}
if (strpos($var, '.') !== false) {
$names = explode('.', $var, 3);
$var = $names[0];
}
if (!isset(self::$_values[$var])) {
return null;
}
switch (count($names)) {
case 2:
if (isset(self::$_values[$var][$names[1]])) {
return self::$_values[$var][$names[1]];
}
break;
case 3:
if (isset(self::$_values[$var][$names[1]][$names[2]])) {
return self::$_values[$var][$names[1]][$names[2]];
}
if (!isset(self::$_values[$var][$names[1]])) {
return null;
}
return Set::classicExtract(self::$_values[$var][$names[1]], $names[2]);
break;
$pointer = &self::$_values;
foreach (explode('.', $var) as $key) {
if (isset($pointer[$key])) {
$pointer = &$pointer[$key];
} else {
return null;
}
}
return null;
return $pointer;
}

/**
Expand Down

0 comments on commit eab2d8a

Please sign in to comment.