debug
This commit is contained in:
@@ -276,6 +276,46 @@ function module_design(string $module): array
|
||||
return $cache[$module];
|
||||
}
|
||||
|
||||
function module_debug_entries(string $module): array
|
||||
{
|
||||
if (preg_match('/[^a-zA-Z0-9_\-]/', $module)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
app()->session()->start();
|
||||
$entries = $_SESSION['module_debug'][$module] ?? [];
|
||||
return is_array($entries) ? array_values(array_filter($entries, 'is_array')) : [];
|
||||
}
|
||||
|
||||
function module_debug_push(string $module, array $entry): void
|
||||
{
|
||||
if (preg_match('/[^a-zA-Z0-9_\-]/', $module)) {
|
||||
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);
|
||||
}
|
||||
|
||||
function module_debug_clear(string $module): void
|
||||
{
|
||||
if (preg_match('/[^a-zA-Z0-9_\-]/', $module)) {
|
||||
return;
|
||||
}
|
||||
|
||||
app()->session()->start();
|
||||
unset($_SESSION['module_debug'][$module]);
|
||||
}
|
||||
|
||||
function module_shell_header(string $module, array $options = []): string
|
||||
{
|
||||
$design = module_design($module);
|
||||
@@ -374,7 +414,53 @@ function module_shell_header(string $module, array $options = []): string
|
||||
|
||||
function module_shell_footer(): string
|
||||
{
|
||||
return '</div></div></div>';
|
||||
$html = '';
|
||||
$module = current_module_name();
|
||||
if (is_string($module) && $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>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user