1e51ef7def
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/ - 12 code-workspace-Files - STATUS-*.md - viele M/D/R-Änderungen an bereits getrackten Files - .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* V2-Plattform — Request-Validierung
|
|
*
|
|
* Schmal — kein vollausgebautes JSON-Schema, sondern feldweise Asserts.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
function v2_validate_required(array $body, array $fields): void {
|
|
$missing = [];
|
|
foreach ($fields as $f) {
|
|
if (!array_key_exists($f, $body) || $body[$f] === null || $body[$f] === '') {
|
|
$missing[] = $f;
|
|
}
|
|
}
|
|
if ($missing) {
|
|
v2_response_error(400, 'missing_fields', 'Pflichtfelder fehlen.', [
|
|
'missing' => $missing,
|
|
]);
|
|
}
|
|
}
|
|
|
|
function v2_validate_enum(string $value, array $allowed, string $fieldName): void {
|
|
if (!in_array($value, $allowed, true)) {
|
|
v2_response_error(400, 'invalid_value', "Ungültiger Wert für '$fieldName'.", [
|
|
'allowed' => $allowed,
|
|
'got' => $value,
|
|
]);
|
|
}
|
|
}
|
|
|
|
function v2_validate_int_range(int $value, int $min, int $max, string $fieldName): void {
|
|
if ($value < $min || $value > $max) {
|
|
v2_response_error(400, 'out_of_range', "Wert für '$fieldName' außerhalb [$min,$max].");
|
|
}
|
|
}
|
|
|
|
function v2_validate_method(string $expected): void {
|
|
$actual = $_SERVER['REQUEST_METHOD'] ?? '';
|
|
if ($actual !== $expected) {
|
|
v2_response_error(405, 'method_not_allowed', "Methode $actual nicht erlaubt, erwartet $expected.");
|
|
}
|
|
}
|
|
|
|
function v2_validate_method_in(array $expected): string {
|
|
$actual = $_SERVER['REQUEST_METHOD'] ?? '';
|
|
if (!in_array($actual, $expected, true)) {
|
|
v2_response_error(405, 'method_not_allowed', "Methode $actual nicht erlaubt.");
|
|
}
|
|
return $actual;
|
|
}
|