Backup #214
| ID | 214 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Framework/Controller.php |
| Version | 3 |
| Typ |
modified |
| Größe | 2.3 KB |
| Hash | c896c7028b432f3b28de8f8e0adc89abbe07bd7d9bad6fac1159c2a98fe8c148 |
| Datum | 2025-12-22 01:41:12 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
namespace Framework;
abstract class Controller
{
protected function csrfToken(): string
{
return CsrfService::getToken();
}
protected function csrfField(): string
{
return CsrfService::getTokenField();
}
protected function validateCsrf(): bool
{
$token = $_POST['_csrf_token'] ?? $_SERVER['HTTP_X_CSRF_TOKEN'] ?? null;
return CsrfService::validateToken($token);
}
protected function requireCsrf(): void
{
if (!$this->validateCsrf()) {
http_response_code(403);
if ($this->isJsonRequest()) {
$this->json(['error' => 'CSRF token invalid'], 403);
} else {
echo 'CSRF token invalid';
}
exit;
}
}
private function isJsonRequest(): bool
{
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
return str_contains($accept, 'application/json') || str_contains($contentType, 'application/json');
}
protected function view(string $name, array $data = []): void
{
$data['csrfField'] = $this->csrfField();
$data['csrfToken'] = $this->csrfToken();
extract($data);
$file = VIEW_PATH . '/' . str_replace('.', '/', $name) . '.php';
if (file_exists($file)) {
require $file;
} else {
throw new \Exception("View not found: {$name}");
}
}
protected function json(mixed $data, int $status = 200): void
{
http_response_code($status);
header('Content-Type: application/json');
echo json_encode($data, JSON_UNESCAPED_UNICODE);
}
protected function redirect(string $url): void
{
header("Location: {$url}");
exit;
}
/**
* @return array<string, mixed>
*/
protected function getJsonInput(): array
{
$input = file_get_contents('php://input');
if ($input === false || $input === '') {
return [];
}
$decoded = json_decode($input, true);
if (!is_array($decoded)) {
return [];
}
return $decoded;
}
protected function jsonError(string $message, int $status = 500): void
{
$this->json(['success' => false, 'error' => $message], $status);
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 2095 |
18 |
modified |
8.6 KB |
2025-12-29 00:20 |
| 1887 |
17 |
modified |
8.6 KB |
2025-12-28 01:00 |
| 1883 |
16 |
modified |
8.5 KB |
2025-12-28 01:00 |
| 1793 |
15 |
modified |
8.5 KB |
2025-12-27 14:09 |
| 1775 |
14 |
modified |
8.1 KB |
2025-12-27 14:03 |
| 1774 |
13 |
modified |
8.0 KB |
2025-12-27 14:03 |
| 1676 |
12 |
modified |
7.6 KB |
2025-12-27 11:45 |
| 1669 |
11 |
modified |
7.4 KB |
2025-12-27 11:29 |
| 877 |
10 |
modified |
7.4 KB |
2025-12-23 09:40 |
| 818 |
9 |
modified |
7.3 KB |
2025-12-23 08:09 |
| 640 |
8 |
modified |
6.9 KB |
2025-12-23 04:47 |
| 628 |
7 |
modified |
6.9 KB |
2025-12-23 04:44 |
| 627 |
6 |
modified |
6.9 KB |
2025-12-23 04:44 |
| 626 |
5 |
modified |
6.0 KB |
2025-12-23 04:44 |
| 496 |
4 |
modified |
4.2 KB |
2025-12-22 15:38 |
| 214 |
3 |
modified |
2.3 KB |
2025-12-22 01:41 |
| 89 |
2 |
modified |
2.2 KB |
2025-12-20 19:16 |
| 87 |
1 |
modified |
1.2 KB |
2025-12-20 19:16 |
← Zurück zur Übersicht