Skip to content

Commit

Permalink
Refactoring Configure::read/Configure::write so keys with <= 2 keys r…
Browse files Browse the repository at this point in the history
…ead/write faster.
  • Loading branch information
markstory committed Nov 22, 2009
1 parent a729fc4 commit 46b965e
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions cake/libs/configure.php
Expand Up @@ -91,11 +91,21 @@ function write($config, $value = null) {
if (strpos($name, '.') === false) {
$_this->{$name} = $value;
} else {
$names = explode('.', $name, 2);
if (!isset($_this->{$names[0]})) {
$_this->{$names[0]} = array();
$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;
}
$_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
}
}

Expand Down Expand Up @@ -149,18 +159,32 @@ function read($var = 'debug') {
}

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};
}

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;
}

/**
Expand Down

0 comments on commit 46b965e

Please sign in to comment.