mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Added Config->getNested(key) and Config->setNested(key, value)
This commit is contained in:
@ -233,6 +233,48 @@ class Config{
|
||||
$this->remove($k);
|
||||
}
|
||||
|
||||
public function setNested($key, $value){
|
||||
$vars = explode(".", $key);
|
||||
$base = array_shift($vars);
|
||||
|
||||
if(!isset($this->config[$base])){
|
||||
$this->config[$base] = [];
|
||||
}
|
||||
|
||||
$base =& $this->config[$base];
|
||||
|
||||
while(count($vars) > 0){
|
||||
$baseKey = array_shift($vars);
|
||||
if(!isset($base[$baseKey])){
|
||||
$base[$baseKey] = [];
|
||||
}
|
||||
$base =& $base[$baseKey];
|
||||
}
|
||||
|
||||
$base = $value;
|
||||
}
|
||||
|
||||
public function getNested($key){
|
||||
$vars = explode(".", $key);
|
||||
$base = array_shift($vars);
|
||||
if(isset($this->config[$base])){
|
||||
$base = $this->config[$base];
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
while(count($vars) > 0){
|
||||
$baseKey = array_shift($vars);
|
||||
if(is_array($base) and isset($base[$baseKey])){
|
||||
$base = $base[$baseKey];
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $k
|
||||
*
|
||||
|
Reference in New Issue
Block a user