Refactoring and cleanup
* Moved logic from entrypoint to a dedicated class. * Disabled automatic flush of state. * Added locking support to prevent multiple instances. * Added logging * Added base interface for CredentialsLoader
This commit is contained in:
@ -15,15 +15,17 @@ class PersistentState
|
||||
public function __construct(string $filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
register_shutdown_function([$this,"flush"]);
|
||||
// register_shutdown_function([$this,"flush"]);
|
||||
if (file_exists($filename)) {
|
||||
$this->state = Yaml::parseFile($filename);
|
||||
$this->state = Yaml::parseFile($filename) ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
public function flush()
|
||||
{
|
||||
if (!$this->dirty) return;
|
||||
$this->dirty = false;
|
||||
|
||||
$yaml = Yaml::dump($this->state);
|
||||
file_put_contents($this->filename."~", $yaml);
|
||||
rename($this->filename."~", $this->filename);
|
||||
|
Reference in New Issue
Block a user