mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-11 04:08:12 +00:00
36 lines
745 B
PHP
36 lines
745 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace FireflyIII\Support\Singleton;
|
||
|
|
|
||
|
|
class PreferencesSingleton
|
||
|
|
{
|
||
|
|
private static ?PreferencesSingleton $instance = null;
|
||
|
|
|
||
|
|
private array $preferences = [];
|
||
|
|
|
||
|
|
private function __construct()
|
||
|
|
{
|
||
|
|
// Private constructor to prevent direct instantiation.
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getInstance(): PreferencesSingleton
|
||
|
|
{
|
||
|
|
if (self::$instance === null) {
|
||
|
|
self::$instance = new PreferencesSingleton();
|
||
|
|
}
|
||
|
|
|
||
|
|
return self::$instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setPreference(string $key, mixed $value): void
|
||
|
|
{
|
||
|
|
$this->preferences[$key] = $value;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getPreference(string $key): mixed
|
||
|
|
{
|
||
|
|
return $this->preferences[$key] ?? null;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|