mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
Added a flag to Config to allow detecting if it has been modified since it was last saved
This commit is contained in:
parent
373f085436
commit
feade9d982
@ -55,6 +55,9 @@ class Config{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
private $jsonOptions = JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING;
|
private $jsonOptions = JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private $changed = false;
|
||||||
|
|
||||||
public static $formats = [
|
public static $formats = [
|
||||||
"properties" => Config::PROPERTIES,
|
"properties" => Config::PROPERTIES,
|
||||||
"cnf" => Config::CNF,
|
"cnf" => Config::CNF,
|
||||||
@ -94,6 +97,14 @@ class Config{
|
|||||||
$this->load($this->file, $this->type);
|
$this->load($this->file, $this->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasChanged() : bool{
|
||||||
|
return $this->changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setChanged(bool $changed = true) : void{
|
||||||
|
$this->changed = $changed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $str
|
* @param string $str
|
||||||
*
|
*
|
||||||
@ -218,6 +229,8 @@ class Config{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->changed = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
@ -237,6 +250,8 @@ class Config{
|
|||||||
throw new \RuntimeException("Attempt to set JSON options for non-JSON config");
|
throw new \RuntimeException("Attempt to set JSON options for non-JSON config");
|
||||||
}
|
}
|
||||||
$this->jsonOptions = $options;
|
$this->jsonOptions = $options;
|
||||||
|
$this->changed = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +268,8 @@ class Config{
|
|||||||
throw new \RuntimeException("Attempt to enable JSON option for non-JSON config");
|
throw new \RuntimeException("Attempt to enable JSON option for non-JSON config");
|
||||||
}
|
}
|
||||||
$this->jsonOptions |= $option;
|
$this->jsonOptions |= $option;
|
||||||
|
$this->changed = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,6 +286,8 @@ class Config{
|
|||||||
throw new \RuntimeException("Attempt to disable JSON option for non-JSON config");
|
throw new \RuntimeException("Attempt to disable JSON option for non-JSON config");
|
||||||
}
|
}
|
||||||
$this->jsonOptions &= ~$option;
|
$this->jsonOptions &= ~$option;
|
||||||
|
$this->changed = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,6 +362,7 @@ class Config{
|
|||||||
|
|
||||||
$base = $value;
|
$base = $value;
|
||||||
$this->nestedCache = [];
|
$this->nestedCache = [];
|
||||||
|
$this->changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -378,6 +398,7 @@ class Config{
|
|||||||
|
|
||||||
public function removeNested(string $key) : void{
|
public function removeNested(string $key) : void{
|
||||||
$this->nestedCache = [];
|
$this->nestedCache = [];
|
||||||
|
$this->changed = true;
|
||||||
|
|
||||||
$vars = explode(".", $key);
|
$vars = explode(".", $key);
|
||||||
|
|
||||||
@ -412,6 +433,7 @@ class Config{
|
|||||||
*/
|
*/
|
||||||
public function set($k, $v = true){
|
public function set($k, $v = true){
|
||||||
$this->config[$k] = $v;
|
$this->config[$k] = $v;
|
||||||
|
$this->changed = true;
|
||||||
foreach($this->nestedCache as $nestedKey => $nvalue){
|
foreach($this->nestedCache as $nestedKey => $nvalue){
|
||||||
if(substr($nestedKey, 0, strlen($k) + 1) === ($k . ".")){
|
if(substr($nestedKey, 0, strlen($k) + 1) === ($k . ".")){
|
||||||
unset($this->nestedCache[$nestedKey]);
|
unset($this->nestedCache[$nestedKey]);
|
||||||
@ -424,6 +446,7 @@ class Config{
|
|||||||
*/
|
*/
|
||||||
public function setAll(array $v){
|
public function setAll(array $v){
|
||||||
$this->config = $v;
|
$this->config = $v;
|
||||||
|
$this->changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -447,6 +470,7 @@ class Config{
|
|||||||
*/
|
*/
|
||||||
public function remove($k){
|
public function remove($k){
|
||||||
unset($this->config[$k]);
|
unset($this->config[$k]);
|
||||||
|
$this->changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -485,6 +509,10 @@ class Config{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($changed > 0){
|
||||||
|
$this->changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
return $changed;
|
return $changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user