From eab2d8aa664813c4c7881802b243edbbed5add43 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 14 Jan 2012 23:22:08 -0430 Subject: [PATCH] Optimizing Configure::read(), now it is possible to read arbitrarily nested keys --- lib/Cake/Core/Configure.php | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index 7871930d1..40d8887dd 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -163,30 +163,15 @@ class Configure { if (isset(self::$_values[$var])) { return self::$_values[$var]; } - if (strpos($var, '.') !== false) { - $names = explode('.', $var, 3); - $var = $names[0]; + $pointer = &self::$_values; + foreach (explode('.', $var) as $key) { + if (isset($pointer[$key])) { + $pointer = &$pointer[$key]; + } else { + return null; + } } - 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; - } - return null; + return $pointer; } /**