mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Refactoring Configure::read/Configure::write so keys with <= 2 keys read/write faster.
This commit is contained in:
parent
a729fc4d62
commit
46b965edba
1 changed files with 34 additions and 10 deletions
|
@ -91,11 +91,21 @@ class Configure extends Object {
|
|||
if (strpos($name, '.') === false) {
|
||||
$_this->{$name} = $value;
|
||||
} else {
|
||||
$names = explode('.', $name, 4);
|
||||
switch (count($names)) {
|
||||
case 2:
|
||||
$_this->{$names[0]}[$names[1]] = $value;
|
||||
break;
|
||||
case 3:
|
||||
$_this->{$names[0]}[$names[1]][$names[2]] = $value;
|
||||
case 4:
|
||||
$names = explode('.', $name, 2);
|
||||
if (!isset($_this->{$names[0]})) {
|
||||
$_this->{$names[0]} = array();
|
||||
}
|
||||
$_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,19 +159,33 @@ class Configure extends Object {
|
|||
}
|
||||
|
||||
if (strpos($var, '.') !== false) {
|
||||
$names = explode('.', $var, 2);
|
||||
$names = explode('.', $var, 3);
|
||||
$var = $names[0];
|
||||
}
|
||||
if (!isset($_this->{$var})) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($names[1])) {
|
||||
return Set::extract($_this->{$var}, $names[1]);
|
||||
}
|
||||
|
||||
if (!isset($names[1])) {
|
||||
return $_this->{$var};
|
||||
}
|
||||
switch (count($names)) {
|
||||
case 2:
|
||||
if (isset($_this->{$var}[$names[1]])) {
|
||||
return $_this->{$var}[$names[1]];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (isset($_this->{$var}[$names[1]][$names[2]])) {
|
||||
return $_this->{$var}[$names[1]][$names[2]];
|
||||
}
|
||||
if (!isset($_this->{$var}[$names[1]])) {
|
||||
return null;
|
||||
}
|
||||
return Set::classicExtract($_this->{$var}[$names[1]], $names[2]);
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to delete a variable from the Configure instance.
|
||||
|
|
Loading…
Reference in a new issue