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,22 +8,22 @@ class Groups
{ {
private static array $groups = []; private static array $groups = [];
public function __construct() { public static function get() {
self::$groups = Cache::remember('groups', 10 * 60, function () { if (count(self::$groups) == 0) {
if (file_exists(config('server_path') . 'config/groups.toml')) { self::$groups = Cache::remember('groups', 10 * 60, function () {
$groups = new TOML\Groups(); if (file_exists(config('server_path') . TOML\Groups::FILE)) {
} $groups = new TOML\Groups();
else { }
$groups = new XML\Groups(); else {
} $groups = new XML\Groups();
}
$groups->load(); $groups->load();
return $groups->getGroups(); return $groups->getGroups();
}); });
} }
public static function getGroups(): array {
return self::$groups; return self::$groups;
} }
} }

View File

@@ -6,19 +6,25 @@ 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) {
if (file_exists(config('server_path') . TOML\Mounts::FILE)) { self::$mounts = Cache::remember('mounts', 10 * 60, function () {
$mounts = new TOML\Mounts(); if (file_exists(config('server_path') . TOML\Mounts::FILE)) {
} $mounts = new TOML\Mounts();
else { }
$mounts = new XML\Mounts(); else {
} $mounts = new XML\Mounts();
}
$mounts->load(); $mounts->load();
return $mounts->get(); return $mounts->get();
}); });
}
return self::$mounts;
} }
} }

View File

@@ -6,19 +6,24 @@ 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 () {
$outfits = new TOML\Outfits(); if (file_exists(config('server_path') . TOML\Outfits::FILE)) {
} $outfits = new TOML\Outfits();
else { } else {
$outfits = new XML\Outfits(); $outfits = new XML\Outfits();
} }
$outfits->load(); $outfits->load();
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.');