sadasd
This commit is contained in:
@@ -6,16 +6,19 @@ declare(strict_types=1);
|
||||
/**
|
||||
* Router für /v1/...
|
||||
*
|
||||
* Wird von /api/index.php aufgerufen:
|
||||
* router_v1_dispatch($segments, $apibasedir)
|
||||
* Wird von /api/index.php so aufgerufen:
|
||||
* router_v1_dispatch($segments)
|
||||
*
|
||||
* $segments[0] ist dann z.B. "browser.quick.test" oder "quickcheck"
|
||||
*
|
||||
* $apibasedir ist der Pfad auf /api (also das Root des API-Vhosts).
|
||||
*/
|
||||
|
||||
function router_v1_dispatch(array $segments, string $apibasedir): void
|
||||
// Basisverzeichnis der API ermitteln (…/api)
|
||||
$apibasedir = dirname(__DIR__);
|
||||
|
||||
function router_v1_dispatch(array $segments): void
|
||||
{
|
||||
global $apibasedir;
|
||||
|
||||
if (empty($segments[0])) {
|
||||
http_response_code(404);
|
||||
echo json_encode([
|
||||
@@ -73,7 +76,6 @@ function router_v1_dispatch(array $segments, string $apibasedir): void
|
||||
try {
|
||||
$result = $handler();
|
||||
|
||||
// Falls der Handler mal kein Array zurückgibt
|
||||
if (!is_array($result)) {
|
||||
$result = [
|
||||
'ok' => false,
|
||||
@@ -83,7 +85,6 @@ function router_v1_dispatch(array $segments, string $apibasedir): void
|
||||
];
|
||||
}
|
||||
|
||||
// HTTP-Status aus Ergebnis ableiten (optional)
|
||||
if (isset($result['ok']) && $result['ok'] === false) {
|
||||
if (!http_response_code()) {
|
||||
http_response_code(400);
|
||||
|
||||
Reference in New Issue
Block a user