Files
kaffeekasse-saas/public/index_test.php
T
2026-06-17 16:45:14 +02:00

160 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use App\Controllers\PlatformController;
use App\Controllers\TenantController;
use App\Core\Response;
use App\Services\SecurityHeadersService;
/**
* Test-Index lädt bootstrap_test.php (SQLite) statt bootstrap.php (MySQL).
* Gleicher Routing-Code wie index.php.
*/
$app = require dirname(__DIR__) . '/app/bootstrap_test.php';
(new SecurityHeadersService())->send();
$database = $app['database'];
$config = $app['config'];
$platform = new PlatformController(
$app['rootPath'],
$config,
$database,
$app['view'],
$app['session'],
$app['csrf']
);
$tenantController = new TenantController(
$database,
$app['view'],
$app['session'],
$app['csrf'],
$config
);
$path = current_path();
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
try {
if ($path === '/' && $method === 'GET') {
$platform->home();
return;
}
if ($path === '/install') {
$method === 'POST' ? $platform->installSubmit() : $platform->installForm();
return;
}
if ($path === '/register') {
$method === 'POST' ? $platform->registerSubmit() : $platform->registerForm();
return;
}
if ($path === '/admin/login') {
$method === 'POST' ? $platform->adminLoginSubmit() : $platform->adminLoginForm();
return;
}
if ($path === '/password/forgot') {
$method === 'POST' ? $platform->passwordResetRequestSubmit() : $platform->passwordResetRequestForm();
return;
}
if ($path === '/reset-password') {
$method === 'POST' ? $platform->passwordResetConfirmSubmit() : $platform->passwordResetConfirmForm();
return;
}
if ($path === '/admin' && $method === 'GET') {
$platform->adminDashboard();
return;
}
if ($path === '/admin/logout' && $method === 'POST') {
$platform->adminLogout();
return;
}
if ($path === '/api/rfid/intake' && $method === 'POST') {
if (!($config['rfid_ingest_enabled'] ?? false)) {
Response::notFound();
return;
}
$tenantController->rfidIngest();
return;
}
if (preg_match('#^/t/([^/]+)(?:/(.*))?$#', $path, $matches)) {
$tenantSlug = rawurldecode($matches[1]);
$subPath = trim((string) ($matches[2] ?? ''), '/');
if ($subPath === '' && $method === 'GET') {
$tenantController->dashboard($tenantSlug);
return;
}
if ($subPath === 'login') {
$method === 'POST' ? $tenantController->loginSubmit($tenantSlug) : $tenantController->loginForm($tenantSlug);
return;
}
if ($subPath === 'logout' && $method === 'POST') {
$tenantController->logout($tenantSlug);
return;
}
if ($subPath === 'members') {
$tenantController->members($tenantSlug);
return;
}
if ($subPath === 'products') {
$tenantController->products($tenantSlug);
return;
}
if ($subPath === 'bookings') {
$tenantController->bookings($tenantSlug);
return;
}
if ($subPath === 'exports/balances.csv' && $method === 'GET') {
$tenantController->exportBalances($tenantSlug);
return;
}
if ($subPath === 'exports/bookings.csv' && $method === 'GET') {
$tenantController->exportBookings($tenantSlug);
return;
}
if ($subPath === 'payments') {
$tenantController->payments($tenantSlug);
return;
}
if ($subPath === 'paper-sheets') {
$tenantController->paperSheets($tenantSlug);
return;
}
if ($subPath === 'rfid') {
$tenantController->rfid($tenantSlug);
return;
}
}
Response::notFound();
} catch (\Throwable $throwable) {
http_response_code(500);
error_log($throwable->__toString());
echo '<h1>Fehler</h1>';
echo '<p>' . e($config['debug'] ? $throwable->getMessage() : 'Die Anfrage konnte gerade nicht verarbeitet werden.') . '</p>';
}