diff --git a/system/src/Items.php b/system/src/Items.php index 396e1053..1e336d92 100644 --- a/system/src/Items.php +++ b/system/src/Items.php @@ -16,7 +16,13 @@ use MyAAC\Models\Spell; class Items { - public static $items; + public static array $items; + + private static string $error = ''; + + public static function getError(): string { + return self::$error; + } public static function load(): bool { $file_path = config('data_path') . 'items/items.toml'; @@ -27,10 +33,14 @@ class Items $items = new Server\XML\Items(); } else { + self::$error = 'Cannot load items.xml or items.toml file. Files not found.'; return false; } - $items->load(); + if (!$items->load()) { + self::$error = $items->getError(); + return false; + } return true; } diff --git a/system/src/Server/Groups.php b/system/src/Server/Groups.php index 3126ad5a..5e393a35 100644 --- a/system/src/Server/Groups.php +++ b/system/src/Server/Groups.php @@ -6,7 +6,7 @@ use MyAAC\Cache\Cache; class Groups { - private static array $groups; + private static array $groups = []; public function __construct() { self::$groups = Cache::remember('groups', 10 * 60, function () { diff --git a/system/src/Server/TOML/Groups.php b/system/src/Server/TOML/Groups.php index 715014f8..9f6e3793 100644 --- a/system/src/Server/TOML/Groups.php +++ b/system/src/Server/TOML/Groups.php @@ -6,7 +6,7 @@ use Devium\Toml\Toml; class Groups { - private array $groups; + private array $groups = []; public function load(): void { @@ -14,7 +14,7 @@ class Groups if(!@file_exists($file)) { error('Error: Cannot load groups.toml. More info in system/logs/error.log file.'); - log_append('error.log', '[OTS_Groups_List.php] Fatal error: Cannot load groups.toml (' . $file . '). It doesnt exist.'); + log_append('error.log', "[OTS_Groups_List.php] Fatal error: Cannot load groups.toml ($file). It doesn't exist."); return; } diff --git a/system/src/Server/TOML/Items.php b/system/src/Server/TOML/Items.php index 3a9bd264..dc957349 100644 --- a/system/src/Server/TOML/Items.php +++ b/system/src/Server/TOML/Items.php @@ -33,7 +33,20 @@ class Items return !in_array($key, ['id', 'article', 'name', 'plural']); }, ARRAY_FILTER_USE_KEY); - $items[$item['id']] = ['article' => $item['article'], 'name' => $item['name'], 'plural' => $item['plural'] ?? '', 'attributes' => $attributes]; + $id = $item['id'] ?? null; + if ($id === null) { + continue; + } + + $article = $item['article'] ?? ''; + $name = $item['name'] ?? ''; + $plural = $item['plural'] ?? ''; + $items[$id] = [ + 'article' => $article, + 'name' => $name, + 'plural' => $plural, + 'attributes' => $attributes, + ]; } $cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/'); diff --git a/system/src/Server/TOML/Vocations.php b/system/src/Server/TOML/Vocations.php index a6b0ff72..f7c53e93 100644 --- a/system/src/Server/TOML/Vocations.php +++ b/system/src/Server/TOML/Vocations.php @@ -6,14 +6,14 @@ use Devium\Toml\Toml; class Vocations { - private array $vocations; - private array $vocationsFrom; + private array $vocations = []; + private array $vocationsFrom = []; public function load(): void { $tomlVocations = glob(config('data_path') . 'vocations/*.toml'); if (count($tomlVocations) <= 0) { - throw new \RuntimeException('ERROR: Cannot load any .toml vocation in the data/vocations folder.'); + throw new \RuntimeException('ERROR: Cannot load any .toml vocation from the data/vocations folder.'); } foreach ($tomlVocations as $file) { diff --git a/system/src/Server/Vocations.php b/system/src/Server/Vocations.php index 40034771..0570a0b9 100644 --- a/system/src/Server/Vocations.php +++ b/system/src/Server/Vocations.php @@ -6,8 +6,8 @@ use MyAAC\Cache\Cache; class Vocations { - private static array $vocations; - private static array $vocationsFrom; + private static array $vocations = []; + private static array $vocationsFrom = []; public function __construct() { $cached = Cache::remember('vocations', 10 * 60, function () { diff --git a/system/src/Server/XML/Groups.php b/system/src/Server/XML/Groups.php index ab262ba4..0b487509 100644 --- a/system/src/Server/XML/Groups.php +++ b/system/src/Server/XML/Groups.php @@ -4,7 +4,7 @@ namespace MyAAC\Server\XML; class Groups { - private array $groups; + private array $groups = []; public function load(): void { @@ -12,7 +12,7 @@ class Groups if(!@file_exists($file)) { error('Error: Cannot load groups.xml. More info in system/logs/error.log file.'); - log_append('error.log', '[OTS_Groups_List.php] Fatal error: Cannot load groups.xml (' . $file . '). It doesnt exist.'); + log_append('error.log', "[OTS_Groups_List.php] Fatal error: Cannot load groups.xml ($file). It doesn't exist."); return; } diff --git a/system/src/Server/XML/Vocations.php b/system/src/Server/XML/Vocations.php index ebc57492..64ad2f33 100644 --- a/system/src/Server/XML/Vocations.php +++ b/system/src/Server/XML/Vocations.php @@ -4,8 +4,8 @@ namespace MyAAC\Server\XML; class Vocations { - private array $vocations; - private array $vocationsFrom; + private array $vocations = []; + private array $vocationsFrom = []; public function load(): void {