Files
KantSites/zentrale/app/Ansicht.php
T
kantarciandClaude Opus 5.5 968d19b611
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s
Add a KantTresor tab to the central registry
KantTresor instances (from 1.82.0) report to /api/kanttresor/melden with the
same key-then-HMAC protocol. The new tab lists them with tenants, disk usage
and failing services; it never offers or accepts an update order, since
KantTresor is updated with ./update.sh on the server. See ADR 124.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 10:02:07 +01:00

71 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace Zentrale;
/**
* Vorlagen als PHP-Dateien. Alles, was ausgegeben wird, geht durch e().
*/
final class Ansicht
{
/** @param string $pfad die Übersicht, auf die adresse() zeigt (KantSites oder KantTresor) */
public function __construct(private string $csrf, private string $pfad = '/')
{
}
/** @param array<string, mixed> $daten */
public function vorlage(string $datei, array $daten): string
{
$v = $this;
extract($daten, EXTR_SKIP);
ob_start();
require $datei;
return (string) ob_get_clean();
}
public function e(mixed $wert): string
{
return htmlspecialchars((string) $wert, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
public function csrf(): string
{
return '<input type="hidden" name="_csrf" value="'.$this->e($this->csrf).'">';
}
/**
* Eine Adresse der Übersicht; leere Werte und Seite 1 fallen weg.
*
* @param array<string, mixed> $werte
*/
public function adresse(array $werte): string
{
$werte = array_filter($werte, static fn (mixed $wert): bool => null !== $wert && '' !== $wert && 1 !== $wert);
return $this->pfad.([] === $werte ? '' : '?'.http_build_query($werte));
}
/** Ein Zeitpunkt in deutscher Ortszeit. */
public function zeit(?string $iso): string
{
if (null === $iso || '' === $iso || false === strtotime($iso)) {
return '–';
}
return (new \DateTimeImmutable($iso))->setTimezone(new \DateTimeZone('Europe/Berlin'))->format('d.m.Y, H:i');
}
/** „vor 5 Minuten“ - für die letzte Meldung. */
public function vor(int $sekunden): string
{
return match (true) {
$sekunden < 90 => 'gerade eben',
$sekunden < 5400 => sprintf('vor %d Minuten', (int) round($sekunden / 60)),
$sekunden < 129600 => sprintf('vor %d Stunden', (int) round($sekunden / 3600)),
default => sprintf('vor %d Tagen', (int) round($sekunden / 86400)),
};
}
}