Backup #87

ID87
Dateipfad/var/www/dev.campus.systemische-tools.de/src/Framework/Controller.php
Version1
Typ modified
Größe1.2 KB
Hashbf9e71cef30d4ef0f02f8982a70c49a849b6ef8c9942c226b6648481d4fd36a4
Datum2025-12-20 19:16:14
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php

namespace Framework;

abstract class Controller
{
    protected function view(string $name, array $data = []): void
    {
        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

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
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