Add a basic singleton to save on queries.

This commit is contained in:
James Cole
2025-08-08 15:44:15 +02:00
parent aaffc125e7
commit 73512b0365
3 changed files with 85 additions and 31 deletions

View File

@@ -0,0 +1,35 @@
<?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;
}
}