mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Added default parameter to Config getters, implements and closes #2398
This commit is contained in:
parent
71d602a4cf
commit
1f9cd6a99b
@ -205,7 +205,7 @@ class Config{
|
|||||||
*
|
*
|
||||||
* @return boolean|mixed
|
* @return boolean|mixed
|
||||||
*/
|
*/
|
||||||
public function &__get($k){
|
public function __get($k){
|
||||||
return $this->get($k);
|
return $this->get($k);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +233,10 @@ class Config{
|
|||||||
$this->remove($k);
|
$this->remove($k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $key
|
||||||
|
* @param $value
|
||||||
|
*/
|
||||||
public function setNested($key, $value){
|
public function setNested($key, $value){
|
||||||
$vars = explode(".", $key);
|
$vars = explode(".", $key);
|
||||||
$base = array_shift($vars);
|
$base = array_shift($vars);
|
||||||
@ -254,13 +258,19 @@ class Config{
|
|||||||
$base = $value;
|
$base = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNested($key){
|
/**
|
||||||
|
* @param $key
|
||||||
|
* @param null $default
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getNested($key, $default = null){
|
||||||
$vars = explode(".", $key);
|
$vars = explode(".", $key);
|
||||||
$base = array_shift($vars);
|
$base = array_shift($vars);
|
||||||
if(isset($this->config[$base])){
|
if(isset($this->config[$base])){
|
||||||
$base = $this->config[$base];
|
$base = $this->config[$base];
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(count($vars) > 0){
|
while(count($vars) > 0){
|
||||||
@ -268,7 +278,7 @@ class Config{
|
|||||||
if(is_array($base) and isset($base[$baseKey])){
|
if(is_array($base) and isset($base[$baseKey])){
|
||||||
$base = $base[$baseKey];
|
$base = $base[$baseKey];
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,25 +287,22 @@ class Config{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $k
|
* @param $k
|
||||||
|
* @param $default
|
||||||
*
|
*
|
||||||
* @return boolean|mixed
|
* @return boolean|mixed
|
||||||
*/
|
*/
|
||||||
public function &get($k){
|
public function get($k, $default = false){
|
||||||
if(isset($this->correct) and ($this->correct === false or !isset($this->config[$k]))){
|
return ($this->correct and isset($this->config[$k])) ? $this->config[$k] : $default;
|
||||||
$false = false;
|
|
||||||
|
|
||||||
return $false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->config[$k];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function &getPath($path){
|
public function getPath($path){
|
||||||
$currPath =& $this->config;
|
$currPath =& $this->config;
|
||||||
foreach(explode(".", $path) as $component){
|
foreach(explode(".", $path) as $component){
|
||||||
if(isset($currPath[$component])){
|
if(isset($currPath[$component])){
|
||||||
@ -309,10 +316,13 @@ class Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function &setPath($path, $value){
|
public function setPath($path, $value){
|
||||||
$currPath =& $this->config;
|
$currPath =& $this->config;
|
||||||
$components = explode(".", $path);
|
$components = explode(".", $path);
|
||||||
$final = array_pop($components);
|
$final = array_pop($components);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user