mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 08:49:42 +00:00
Fixed config type detection, fixed configs being saved empty
Fixes LegendOfMCPE/EssentialsPE#354 When the config file didn't exist, no type detection was performed. This resulted in the case statement for Config->save() falling through and not writing anything to the file.
This commit is contained in:
parent
adbc298909
commit
ae612b913e
@ -110,17 +110,11 @@ class Config{
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function load($file, $type = Config::DETECT, $default = []){
|
public function load(string $file, int $type = Config::DETECT, array $default = []){
|
||||||
$this->correct = true;
|
$this->correct = true;
|
||||||
$this->type = (int) $type;
|
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
if(!is_array($default)){
|
|
||||||
$default = [];
|
$this->type = $type;
|
||||||
}
|
|
||||||
if(!file_exists($file)){
|
|
||||||
$this->config = $default;
|
|
||||||
$this->save();
|
|
||||||
}else{
|
|
||||||
if($this->type === Config::DETECT){
|
if($this->type === Config::DETECT){
|
||||||
$extension = explode(".", basename($this->file));
|
$extension = explode(".", basename($this->file));
|
||||||
$extension = strtolower(trim(array_pop($extension)));
|
$extension = strtolower(trim(array_pop($extension)));
|
||||||
@ -130,6 +124,11 @@ class Config{
|
|||||||
$this->correct = false;
|
$this->correct = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!file_exists($file)){
|
||||||
|
$this->config = $default;
|
||||||
|
$this->save();
|
||||||
|
}else{
|
||||||
if($this->correct === true){
|
if($this->correct === true){
|
||||||
$content = file_get_contents($this->file);
|
$content = file_get_contents($this->file);
|
||||||
switch($this->type){
|
switch($this->type){
|
||||||
@ -202,6 +201,8 @@ class Config{
|
|||||||
case Config::ENUM:
|
case Config::ENUM:
|
||||||
$content = implode("\r\n", array_keys($this->config));
|
$content = implode("\r\n", array_keys($this->config));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new \InvalidStateException("Config type is unknown, has not been set or not detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($async){
|
if($async){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user