Permalink
Browse files

Optimizing Configure::read(), now it is possible to read arbitrarily …

…nested keys
  • Loading branch information...
1 parent 3a48f64 commit eab2d8aa664813c4c7881802b243edbbed5add43 @lorenzo lorenzo committed Jan 15, 2012
Showing with 8 additions and 23 deletions.
  1. +8 −23 lib/Cake/Core/Configure.php
@@ -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;
}
/**

0 comments on commit eab2d8a

Please sign in to comment.