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:
2022-03-09 00:38:57 +01:00
parent 1f44d9f44b
commit ec1659e96d
10 changed files with 493 additions and 172 deletions

View File

@ -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);