Use static methods instead, looks better

This commit is contained in:
slawkens
2026-02-27 15:25:06 +01:00
parent f975bd2f2a
commit 4ca79a1e85
5 changed files with 48 additions and 36 deletions

View File

@@ -47,8 +47,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
return; return;
} }
$groups = new Groups(); foreach(Groups::get() as $id => $info) {
foreach($groups->getGroups() as $id => $info) {
$this->groups[$id] = new OTS_Group($info); $this->groups[$id] = new OTS_Group($info);
} }
} }

View File

@@ -8,9 +8,10 @@ class Groups
{ {
private static array $groups = []; private static array $groups = [];
public function __construct() { public static function get() {
if (count(self::$groups) == 0) {
self::$groups = Cache::remember('groups', 10 * 60, function () { self::$groups = Cache::remember('groups', 10 * 60, function () {
if (file_exists(config('server_path') . 'config/groups.toml')) { if (file_exists(config('server_path') . TOML\Groups::FILE)) {
$groups = new TOML\Groups(); $groups = new TOML\Groups();
} }
else { else {
@@ -23,7 +24,6 @@ class Groups
}); });
} }
public static function getGroups(): array {
return self::$groups; return self::$groups;
} }
} }

View File

@@ -6,9 +6,12 @@ use MyAAC\Cache\Cache;
class Mounts class Mounts
{ {
private static array $mounts = [];
public static function get() public static function get()
{ {
return Cache::remember('mounts', 10 * 60, function () { if (count(self::$mounts) == 0) {
self::$mounts = Cache::remember('mounts', 10 * 60, function () {
if (file_exists(config('server_path') . TOML\Mounts::FILE)) { if (file_exists(config('server_path') . TOML\Mounts::FILE)) {
$mounts = new TOML\Mounts(); $mounts = new TOML\Mounts();
} }
@@ -21,4 +24,7 @@ class Mounts
return $mounts->get(); return $mounts->get();
}); });
} }
return self::$mounts;
}
} }

View File

@@ -6,13 +6,15 @@ use MyAAC\Cache\Cache;
class Outfits class Outfits
{ {
private static array $outfits = [];
public static function get() public static function get()
{ {
return Cache::remember('outfits', 10 * 60, function () { if (count(self::$outfits) == 0) {
if (file_exists(config('server_path') . 'config/outfits.toml')) { self::$outfits = Cache::remember('outfits', 10 * 60, function () {
if (file_exists(config('server_path') . TOML\Outfits::FILE)) {
$outfits = new TOML\Outfits(); $outfits = new TOML\Outfits();
} } else {
else {
$outfits = new XML\Outfits(); $outfits = new XML\Outfits();
} }
@@ -21,4 +23,7 @@ class Outfits
return $outfits->getOutfits(); return $outfits->getOutfits();
}); });
} }
return self::$outfits;
}
} }

View File

@@ -8,9 +8,11 @@ class Groups
{ {
private array $groups = []; private array $groups = [];
const FILE = 'config/groups.toml';
public function load(): void public function load(): void
{ {
$file = config('server_path') . 'config/groups.toml'; $file = config('server_path') . self::FILE;
if(!@file_exists($file)) { if(!@file_exists($file)) {
error('Error: Cannot load groups.toml. More info in system/logs/error.log file.'); error('Error: Cannot load groups.toml. More info in system/logs/error.log file.');