mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Add a basic singleton to save on queries.
This commit is contained in:
35
app/Support/Singleton/PreferencesSingleton.php
Normal file
35
app/Support/Singleton/PreferencesSingleton.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user