mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Optimizing Configure::read(), now it is possible to read arbitrarily nested keys
This commit is contained in:
parent
3a48f64370
commit
eab2d8aa66
1 changed files with 8 additions and 23 deletions
|
@ -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];
|
||||
}
|
||||
if (!isset(self::$_values[$var])) {
|
||||
$pointer = &self::$_values;
|
||||
foreach (explode('.', $var) as $key) {
|
||||
if (isset($pointer[$key])) {
|
||||
$pointer = &$pointer[$key];
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue