yyxx
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-05 23:46:23 +02:00
parent e335a8d5bf
commit 48b7583f19
9 changed files with 528 additions and 277 deletions

View File

@@ -276,20 +276,94 @@ function module_design(string $module): array
return $cache[$module];
}
function nexus_debug_settings_key(): string
{
return '__nexus_debug__';
}
function nexus_debug_configured(): bool
{
try {
$settings = modules()->settings(nexus_debug_settings_key());
} catch (\Throwable $e) {
return false;
}
$value = $settings['enabled'] ?? '0';
return $value === true || $value === 1 || $value === '1' || $value === 'true';
}
function nexus_debug_enabled(): bool
{
if (!nexus_debug_configured()) {
return false;
}
if (function_exists('auth_enabled') && auth_enabled()) {
return auth_is_admin();
}
return true;
}
function nexus_debug_entries(): array
{
if (!nexus_debug_enabled()) {
return [];
}
app()->session()->start();
$entries = $_SESSION['nexus_debug_entries'] ?? [];
return is_array($entries) ? array_values(array_filter($entries, 'is_array')) : [];
}
function nexus_debug_push(string $source, array $entry): void
{
if (!nexus_debug_enabled()) {
return;
}
$source = trim($source);
if ($source === '') {
$source = 'nexus';
}
app()->session()->start();
if (!isset($_SESSION['nexus_debug_entries']) || !is_array($_SESSION['nexus_debug_entries'])) {
$_SESSION['nexus_debug_entries'] = [];
}
$entry['source'] = $entry['source'] ?? $source;
$entry['at'] = $entry['at'] ?? date('Y-m-d H:i:s');
array_unshift($_SESSION['nexus_debug_entries'], $entry);
$_SESSION['nexus_debug_entries'] = array_slice($_SESSION['nexus_debug_entries'], 0, 250);
}
function nexus_debug_clear(?string $source = null): void
{
app()->session()->start();
if ($source === null || trim($source) === '') {
unset($_SESSION['nexus_debug_entries']);
return;
}
$entries = $_SESSION['nexus_debug_entries'] ?? [];
if (!is_array($entries)) {
return;
}
$_SESSION['nexus_debug_entries'] = array_values(array_filter($entries, static function ($entry) use ($source): bool {
return !is_array($entry) || (string) ($entry['source'] ?? '') !== $source;
}));
}
function module_debug_enabled(string $module): bool
{
if (preg_match('/[^a-zA-Z0-9_\-]/', $module)) {
return false;
}
try {
$settings = modules()->settings($module);
} catch (\Throwable $e) {
return false;
}
$value = $settings['debug_enabled'] ?? '0';
return $value === true || $value === 1 || $value === '1' || $value === 'true';
return nexus_debug_enabled();
}
function module_debug_entries(string $module): array
@@ -301,9 +375,9 @@ function module_debug_entries(string $module): array
return [];
}
app()->session()->start();
$entries = $_SESSION['module_debug'][$module] ?? [];
return is_array($entries) ? array_values(array_filter($entries, 'is_array')) : [];
return array_values(array_filter(nexus_debug_entries(), static function ($entry) use ($module): bool {
return is_array($entry) && (string) ($entry['source'] ?? '') === $module;
}));
}
function module_debug_push(string $module, array $entry): void
@@ -315,17 +389,7 @@ function module_debug_push(string $module, array $entry): void
return;
}
app()->session()->start();
if (!isset($_SESSION['module_debug']) || !is_array($_SESSION['module_debug'])) {
$_SESSION['module_debug'] = [];
}
if (!isset($_SESSION['module_debug'][$module]) || !is_array($_SESSION['module_debug'][$module])) {
$_SESSION['module_debug'][$module] = [];
}
$entry['at'] = $entry['at'] ?? date('Y-m-d H:i:s');
array_unshift($_SESSION['module_debug'][$module], $entry);
$_SESSION['module_debug'][$module] = array_slice($_SESSION['module_debug'][$module], 0, 25);
nexus_debug_push($module, $entry);
}
function module_debug_clear(string $module): void
@@ -334,8 +398,7 @@ function module_debug_clear(string $module): void
return;
}
app()->session()->start();
unset($_SESSION['module_debug'][$module]);
nexus_debug_clear($module);
}
function module_shell_header(string $module, array $options = []): string
@@ -442,53 +505,7 @@ function module_shell_header(string $module, array $options = []): string
function module_shell_footer(): string
{
$html = '';
$module = current_module_name();
if (is_string($module) && $module !== '' && module_debug_enabled($module)) {
if ((string) ($_GET['module_debug_clear'] ?? '') === '1') {
module_debug_clear($module);
}
$entries = module_debug_entries($module);
$currentPath = app()->request()->path();
$clearHref = $currentPath . '?module_debug_clear=1';
$html .= '<section class="module-debug">';
$html .= '<details class="module-debug-details"' . ($entries !== [] ? ' open' : '') . '>';
$html .= '<summary class="module-debug-summary">';
$html .= '<span>Debug</span>';
$html .= '<span class="module-debug-meta">' . e((string) count($entries)) . ' Eintraege</span>';
$html .= '</summary>';
$html .= '<div class="module-debug-body">';
$html .= '<div class="module-debug-toolbar">';
$html .= '<div class="muted">Standard-Debugbereich des Moduls. Zeigt die letzten Request-/Response-Daten der aktuellen Sitzung.</div>';
$html .= '<a class="module-button module-button--ghost module-button--small" href="' . e($clearHref) . '">Debug leeren</a>';
$html .= '</div>';
if ($entries === []) {
$html .= '<div class="module-debug-empty">Noch keine Debug-Daten vorhanden.</div>';
} else {
foreach ($entries as $index => $entry) {
$label = trim((string) ($entry['label'] ?? ('Eintrag ' . ($index + 1))));
$at = trim((string) ($entry['at'] ?? ''));
$payload = json_encode($entry, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if (!is_string($payload)) {
$payload = '{}';
}
$html .= '<details class="module-debug-entry"' . ($index === 0 ? ' open' : '') . '>';
$html .= '<summary><strong>' . e($label) . '</strong>' . ($at !== '' ? '<span class="module-debug-entry-time">' . e($at) . '</span>' : '') . '</summary>';
$html .= '<pre class="module-debug-pre">' . e($payload) . '</pre>';
$html .= '</details>';
}
}
$html .= '</div>';
$html .= '</details>';
$html .= '</section>';
}
return $html . '</div></div></div>';
return '</div></div></div>';
}
/**