adasd
This commit is contained in:
@@ -22,3 +22,5 @@ spl_autoload_register(static function (string $class): void {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
require_once dirname(__DIR__) . '/ModulesCore/LegacyCompat.php';
|
||||
|
||||
220
src/ModulesCore/LegacyCompat.php
Normal file
220
src/ModulesCore/LegacyCompat.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ModulesCore {
|
||||
|
||||
use App\ConfigLoader;
|
||||
use App\KeycloakAuth;
|
||||
use RuntimeException;
|
||||
|
||||
final class LegacyCompat
|
||||
{
|
||||
private static ?LegacyCompatAppContext $appContext = null;
|
||||
private static ?LegacyCompatModuleRuntime $moduleRuntime = null;
|
||||
|
||||
public static function app(): LegacyCompatAppContext
|
||||
{
|
||||
if (self::$appContext === null) {
|
||||
self::$appContext = new LegacyCompatAppContext(self::projectRoot());
|
||||
}
|
||||
|
||||
return self::$appContext;
|
||||
}
|
||||
|
||||
public static function modules(): LegacyCompatModuleRuntime
|
||||
{
|
||||
if (self::$moduleRuntime === null) {
|
||||
self::$moduleRuntime = new LegacyCompatModuleRuntime(self::projectRoot());
|
||||
}
|
||||
|
||||
return self::$moduleRuntime;
|
||||
}
|
||||
|
||||
public static function projectRoot(): string
|
||||
{
|
||||
return dirname(__DIR__, 2);
|
||||
}
|
||||
}
|
||||
|
||||
final class LegacyCompatAppContext
|
||||
{
|
||||
private ?LegacyCompatConfig $config = null;
|
||||
private ?LegacyCompatAuthContext $auth = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly string $projectRoot,
|
||||
) {
|
||||
}
|
||||
|
||||
public function config(): LegacyCompatConfig
|
||||
{
|
||||
if ($this->config === null) {
|
||||
$this->config = new LegacyCompatConfig($this->projectRoot);
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function auth(): LegacyCompatAuthContext
|
||||
{
|
||||
if ($this->auth === null) {
|
||||
$this->auth = new LegacyCompatAuthContext($this->projectRoot);
|
||||
}
|
||||
|
||||
return $this->auth;
|
||||
}
|
||||
}
|
||||
|
||||
final class LegacyCompatConfig
|
||||
{
|
||||
/** @var array<string, mixed> */
|
||||
public array $dbConfig;
|
||||
|
||||
public function __construct(string $projectRoot)
|
||||
{
|
||||
$baseDb = ConfigLoader::load($projectRoot, 'base_db');
|
||||
$db = ConfigLoader::load($projectRoot, 'db_settings_basic');
|
||||
$baseDbEnabled = (bool) ($baseDb['enabled'] ?? false);
|
||||
$baseDbConfig = is_array($baseDb['db'] ?? null) ? $baseDb['db'] : [];
|
||||
$dbConfig = is_array($db) ? $db : [];
|
||||
|
||||
$this->dbConfig = $baseDbEnabled && $baseDbConfig !== []
|
||||
? $baseDbConfig
|
||||
: $dbConfig;
|
||||
}
|
||||
}
|
||||
|
||||
final class LegacyCompatAuthContext
|
||||
{
|
||||
private ?KeycloakAuth $auth = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly string $projectRoot,
|
||||
) {
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->auth()->isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function user(): ?array
|
||||
{
|
||||
$session = $_SESSION['desktop_auth']['user'] ?? null;
|
||||
|
||||
return is_array($session) ? $session : null;
|
||||
}
|
||||
|
||||
private function auth(): KeycloakAuth
|
||||
{
|
||||
if ($this->auth === null) {
|
||||
$this->auth = new KeycloakAuth(ConfigLoader::load($this->projectRoot, 'keycloak'));
|
||||
}
|
||||
|
||||
return $this->auth;
|
||||
}
|
||||
}
|
||||
|
||||
final class LegacyCompatModuleRuntime
|
||||
{
|
||||
/** @var array<string, array<string, mixed>> */
|
||||
private array $settingsCache = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly string $projectRoot,
|
||||
) {
|
||||
}
|
||||
|
||||
public function isEnabled(string $moduleName): bool
|
||||
{
|
||||
return is_dir($this->modulePath($moduleName));
|
||||
}
|
||||
|
||||
public function hasFunction(string $moduleName, string $functionName): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function call(string $moduleName, string $functionName, mixed ...$args): mixed
|
||||
{
|
||||
throw new RuntimeException(sprintf(
|
||||
'Modulfunktion %s::%s ist in dieser Laufzeit nicht registriert.',
|
||||
$moduleName,
|
||||
$functionName
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function settings(string $moduleName): array
|
||||
{
|
||||
if (isset($this->settingsCache[$moduleName])) {
|
||||
return $this->settingsCache[$moduleName];
|
||||
}
|
||||
|
||||
$configPath = $this->modulePath($moduleName) . '/config/module.php';
|
||||
if (!is_file($configPath)) {
|
||||
return $this->settingsCache[$moduleName] = [];
|
||||
}
|
||||
|
||||
$config = require $configPath;
|
||||
|
||||
return $this->settingsCache[$moduleName] = is_array($config) ? $config : [];
|
||||
}
|
||||
|
||||
private function modulePath(string $moduleName): string
|
||||
{
|
||||
return $this->projectRoot . '/modules/' . trim($moduleName, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
use ModulesCore\LegacyCompat;
|
||||
|
||||
if (!function_exists('app')) {
|
||||
function app(): \ModulesCore\LegacyCompatAppContext
|
||||
{
|
||||
return LegacyCompat::app();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('modules')) {
|
||||
function modules(): \ModulesCore\LegacyCompatModuleRuntime
|
||||
{
|
||||
return LegacyCompat::modules();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('module_fn')) {
|
||||
function module_fn(string $moduleName, string $functionName, mixed ...$args): mixed
|
||||
{
|
||||
return modules()->call($moduleName, $functionName, ...$args);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('module_debug_enabled')) {
|
||||
function module_debug_enabled(string $moduleName): bool
|
||||
{
|
||||
$settings = modules()->settings($moduleName);
|
||||
$debug = $settings['debug'] ?? null;
|
||||
|
||||
return is_array($debug) && (bool) ($debug['enabled'] ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('nexus_display_timezone_name')) {
|
||||
function nexus_display_timezone_name(): string
|
||||
{
|
||||
$timezone = trim((string) date_default_timezone_get());
|
||||
|
||||
return $timezone !== '' ? $timezone : 'Europe/Berlin';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user