Added Config::getPath() and Config::setPath()

This commit is contained in:
Shoghi Cervantes 2014-04-05 10:36:18 +02:00
parent e390374c74
commit 7be9ea68c7

View File

@ -248,6 +248,40 @@ class Config{
return $this->config[$k];
}
/**
* @param string $path
*
* @return mixed
*/
public function &getPath($path){
$currPath =& $this->config;
foreach(explode(".", $path) as $component){
if(isset($currPath[$component])){
$currPath =& $currPath[$component];
}else{
$currPath = null;
}
}
return $currPath;
}
/**
* @param string $path
* @param mixed $value
*/
public function &setPath($path, $value){
$currPath =& $this->config;
$components = explode(".", $path);
$final = array_pop($components);
foreach($components as $component){
if(!isset($currPath[$component])){
$currPath[$component] = array();
}
$currPath =& $currPath[$component];
}
$currPath[$final] = $value;
}
/**
* @param string $k key to be set
* @param bool $v value to set key