philippurbschat.de/test/bootstrap.php
Philipp Urbschat f393beb7ff
feat: inkubator-standard & modul-autodiscovery
- Dynamische Modulerkennung via module.json in ModuleService.php
- Kaskadierender Env-Loader fuer zentrale API-Keys (GEMINI_API_KEY)
- Graceful Auth fuer alle Subprojekte (dinos, plants, storymachine, test)
- Wiederverwendbares Starter-Template in _template/
- test-Modul auf philippurbschat.de Dark-Design modernisiert
2026-09-13 00:23:16 +02:00

58 lines
1.9 KiB
PHP

<?php
/**
* Modul-Bootstrap für test
*/
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$authPath = __DIR__ . '/../auth.php';
$isHostedOnMainSite = file_exists($authPath);
if ($isHostedOnMainSite && php_sapi_name() !== 'cli') {
$current_project = basename(__DIR__);
require_once $authPath;
}
$currentUser = $_SESSION['user_email'] ?? 'Gast / Standalone';
$isAdmin = !empty($_SESSION['is_admin']);
if (!function_exists('module_env')) {
function module_env(string $key, ?string $default = null): ?string {
static $envCache = null;
if ($envCache === null) {
$envCache = [];
$candidates = [
__DIR__ . '/.env',
__DIR__ . '/../home/.env',
__DIR__ . '/../.env'
];
foreach ($candidates as $file) {
if (file_exists($file)) {
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines !== false) {
foreach ($lines as $line) {
$line = trim($line);
if ($line === '' || $line[0] === '#') continue;
if (strpos($line, '=') !== false) {
list($k, $v) = explode('=', $line, 2);
$cleanKey = trim($k);
if (!isset($envCache[$cleanKey])) {
$envCache[$cleanKey] = trim(trim($v), '"\'');
}
}
}
}
}
}
}
if (isset($envCache[$key])) {
return $envCache[$key];
}
$sysEnv = getenv($key);
if ($sysEnv !== false && $sysEnv !== '') {
return $sysEnv;
}
return $_ENV[$key] ?? $default;
}
}