repository = new ContractRepository(); } /** * GET /contracts */ public function index(): void { $filters = []; if (isset($_GET['status']) && $_GET['status'] !== '') { $filters['status'] = $_GET['status']; } $contracts = $this->repository->findAll($filters); $stats = $this->repository->getStatistics(); $this->view('contracts.index', [ 'title' => 'Contracts', 'contracts' => $contracts, 'stats' => $stats, 'currentStatus' => $_GET['status'] ?? '', ]); } /** * GET /contracts/new */ public function contractNew(): void { $this->view('contracts.new', [ 'title' => 'Neuer Contract', ]); } /** * POST /contracts */ public function store(): void { $this->requireCsrf(); $name = trim($_POST['name'] ?? ''); $version = trim($_POST['version'] ?? '1.0'); $yamlContent = $_POST['yaml_content'] ?? ''; $scopeDescription = trim($_POST['scope_description'] ?? ''); $status = $_POST['status'] ?? 'active'; if ($name === '' || $yamlContent === '') { $_SESSION['error'] = 'Name und YAML-Inhalt sind erforderlich.'; header('Location: /contracts/new'); exit; } // YAML-Syntax validieren try { yaml_parse($yamlContent); } catch (\Exception $e) { $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage(); header('Location: /contracts/new'); exit; } $contractId = $this->repository->create([ 'name' => $name, 'version' => $version, 'yaml_content' => $yamlContent, 'scope_description' => $scopeDescription, 'status' => $status, ]); $_SESSION['success'] = 'Contract erfolgreich erstellt.'; header('Location: /contracts/' . $contractId); exit; } /** * GET /contracts/{id} */ public function show(string $id): void { $contract = $this->repository->findById((int) $id); if ($contract === null) { http_response_code(404); echo 'Contract nicht gefunden'; return; } $history = $this->repository->getHistory((int) $id); $validations = $this->repository->getValidations((int) $id, 10); $this->view('contracts.show', [ 'title' => $contract['name'], 'contract' => $contract, 'history' => $history, 'validations' => $validations, ]); } /** * GET /contracts/{id}/edit */ public function edit(string $id): void { $contract = $this->repository->findById((int) $id); if ($contract === null) { http_response_code(404); echo 'Contract nicht gefunden'; return; } $this->view('contracts.edit', [ 'title' => 'Contract bearbeiten: ' . $contract['name'], 'contract' => $contract, ]); } /** * POST /contracts/{id} */ public function update(string $id): void { $this->requireCsrf(); $contract = $this->repository->findById((int) $id); if ($contract === null) { http_response_code(404); echo 'Contract nicht gefunden'; return; } $yamlContent = $_POST['yaml_content'] ?? ''; $newVersion = trim($_POST['new_version'] ?? ''); $changeDescription = trim($_POST['change_description'] ?? ''); if ($yamlContent === '' || $newVersion === '') { $_SESSION['error'] = 'YAML-Inhalt und neue Version sind erforderlich.'; header('Location: /contracts/' . $id . '/edit'); exit; } // YAML-Syntax validieren try { yaml_parse($yamlContent); } catch (\Exception $e) { $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage(); header('Location: /contracts/' . $id . '/edit'); exit; } $this->repository->createNewVersion( (int) $id, $yamlContent, $newVersion, $changeDescription ); $_SESSION['success'] = 'Contract auf Version ' . $newVersion . ' aktualisiert.'; header('Location: /contracts/' . $id); exit; } /** * POST /contracts/{id}/validate */ public function validate(string $id): void { $contract = $this->repository->findById((int) $id); if ($contract === null) { http_response_code(404); echo 'Contract nicht gefunden'; return; } $result = $this->repository->runValidation((int) $id); $_SESSION['validation_result'] = $result; header('Location: /contracts/' . $id); exit; } /** * POST /contracts/{id}/deprecate */ public function deprecate(string $id): void { $contract = $this->repository->findById((int) $id); if ($contract === null) { http_response_code(404); echo 'Contract nicht gefunden'; return; } $this->repository->deprecate((int) $id); $_SESSION['success'] = 'Contract als deprecated markiert.'; header('Location: /contracts/' . $id); exit; } }