Files
firefly-iii/app/Support/Singleton/PreferencesSingleton.php
T

42 lines
849 B
PHP
Raw Normal View History

2025-08-08 15:44:15 +02:00
<?php
2025-08-08 21:03:45 +02:00
declare(strict_types=1);
2025-08-08 15:44:15 +02:00
namespace FireflyIII\Support\Singleton;
class PreferencesSingleton
{
private static ?PreferencesSingleton $instance = null;
2025-08-08 21:03:45 +02:00
private array $preferences = [];
2025-08-08 15:44:15 +02:00
private function __construct()
{
// Private constructor to prevent direct instantiation.
}
2025-08-08 21:03:45 +02:00
public static function getInstance(): self
2025-08-08 15:44:15 +02:00
{
2025-08-08 21:03:45 +02:00
if (null === self::$instance) {
self::$instance = new self();
2025-08-08 15:44:15 +02:00
}
return self::$instance;
}
2025-08-08 21:03:45 +02:00
public function resetPreferences(): void
{
2025-08-08 20:18:04 +02:00
$this->preferences = [];
}
2025-08-08 15:44:15 +02:00
public function setPreference(string $key, mixed $value): void
{
$this->preferences[$key] = $value;
}
public function getPreference(string $key): mixed
{
return $this->preferences[$key] ?? null;
}
}