core/source/conf.php

115 lines
1.4 KiB
PHP
Raw Normal View History

2025-09-09 12:07:53 +02:00
<?php
namespace davigil\conf;
2025-09-09 19:43:23 +02:00
/**
*/
class struct_auth
{
public string $kind;
public $data;
}
2025-09-09 23:17:19 +02:00
/**
*/
class struct_source_data_ics_feed
{
public string $url;
public bool $combined;
public int $lifetime;
}
2025-09-09 19:43:23 +02:00
/**
*/
class struct_source
{
public string $kind;
public $data;
}
/**
*/
class struct_settings
{
public string $timezone;
}
/**
*/
class struct_root
{
public struct_auth $auth;
public struct_source $source;
public struct_settings $settings;
}
2025-09-09 12:07:53 +02:00
/**
*/
class _state
{
2025-09-09 19:43:23 +02:00
public static ?struct_root $data = null;
2025-09-09 12:07:53 +02:00
}
/**
*/
function load(
string $path
) : void
{
2025-09-09 19:43:23 +02:00
$data_raw = \json_decode(
2025-09-09 12:07:53 +02:00
\file_get_contents(
$path
),
true
);
2025-09-09 19:43:23 +02:00
{
$data = new struct_root();
// auth
{
$auth = new struct_auth();
$auth->kind = (($data_raw['auth'] ?? [])['kind'] ?? 'none');
$auth->data = (($data_raw['auth'] ?? [])['data'] ?? null);
$data->auth = $auth;
}
// source
{
$source = new struct_source();
$source->kind = $data_raw['source']['kind'];
$source->data = ($data_raw['source']['data'] ?? null);
$data->source = $source;
}
// settings
{
$settings = new struct_settings();
$settings->timezone = (($data_raw['settings'] ?? [])['timezone'] ?? 'UTC');
$data->settings = $settings;
}
_state::$data = $data;
}
2025-09-09 12:07:53 +02:00
}
/**
*/
function get(
2025-09-09 19:43:23 +02:00
) : struct_root
2025-09-09 12:07:53 +02:00
{
2025-09-09 23:17:19 +02:00
if (_state::$data === null)
{
throw (new \Exception('not yet loaded'));
}
else
{
return _state::$data;
}
2025-09-09 12:07:53 +02:00
}
?>