mirror of
https://github.com/slawkens/myaac.git
synced 2026-04-23 10:53:32 +02:00
[WIP] Initial Blacktek support - groups, vocations, items
items.toml loading through custom parser - no .toml reader that I tested can read it
This commit is contained in:
43
system/src/Server/TOML/Items.php
Normal file
43
system/src/Server/TOML/Items.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Server\TOML;
|
||||
|
||||
use MyAAC\Cache\PHP as CachePHP;
|
||||
|
||||
class Items
|
||||
{
|
||||
private string $error;
|
||||
|
||||
public function getError(): string
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function load(): bool
|
||||
{
|
||||
$file_path = config('data_path') . 'items/items.toml';
|
||||
if (!file_exists($file_path)) {
|
||||
$this->error = 'Cannot load file ' . $file_path;
|
||||
return false;
|
||||
}
|
||||
|
||||
//$toml = file_get_contents($file_path);
|
||||
//$items = \Devium\Toml\Toml::decode($toml, asArray: false);
|
||||
|
||||
$itemsParser = new ItemsParser();
|
||||
$itemsParsed = $itemsParser->parse($file_path);
|
||||
|
||||
$items = [];
|
||||
foreach ($itemsParsed as $item) {
|
||||
$attributes = array_filter($item, function ($key) {
|
||||
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];
|
||||
}
|
||||
|
||||
$cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');
|
||||
$cache_php->set('items', $items, 5 * 365 * 24 * 60 * 60);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user