mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Added Config::getPath() and Config::setPath()
This commit is contained in:
parent
e390374c74
commit
7be9ea68c7
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user