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:
39
src/State/Log.php
Normal file
39
src/State/Log.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\FreshDocker\State;
|
||||
|
||||
class Log
|
||||
{
|
||||
private bool $verbose = false;
|
||||
|
||||
private array $log = [];
|
||||
|
||||
public function __construct(bool $verbose=false)
|
||||
{
|
||||
$this->verbose = $verbose;
|
||||
}
|
||||
|
||||
public function setVerbose(bool $verbose)
|
||||
{
|
||||
$this->verbose = $verbose;
|
||||
}
|
||||
|
||||
public function append(string $message)
|
||||
{
|
||||
array_push($this->log, $message);
|
||||
if ($this->verbose) {
|
||||
fwrite(STDOUT, $message . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
public function flush()
|
||||
{
|
||||
if ($this->verbose) return;
|
||||
fwrite(STDOUT, join("\n", $this->log)."\n");
|
||||
}
|
||||
|
||||
public function asString(): string
|
||||
{
|
||||
return join("\n", $this->log);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user