mirror of
https://github.com/slawkens/myaac.git
synced 2026-03-16 16:03:31 +01:00
Use static methods instead, looks better
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.');
|
||||||
|
|||||||
Reference in New Issue
Block a user