black-sheep-bluff/app/Support/helpers.php
2026-09-18 06:46:56 +02:00

40 lines
1 KiB
PHP

<?php
declare(strict_types=1);
/**
* Globale Helfer-Funktionen (I/O + Normalisierung).
* Werden vom Kernel früh eingebunden und stehen allen Controllern/Services
* im globalen Namespace zur Verfügung (1:1 aus der alten api.php übernommen).
*/
if (!function_exists('respond')) {
function respond(array $data, int $status = 200): never
{
http_response_code($status);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;
}
}
if (!function_exists('input')) {
function input(): array
{
$raw = file_get_contents('php://input') ?: '';
$data = json_decode($raw, true);
return is_array($data) ? $data : [];
}
}
if (!function_exists('slugCode')) {
function slugCode(string $value): string
{
return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper($value)) ?? '', 0, 12);
}
}
if (!function_exists('playerKey')) {
function playerKey(string $name): string
{
return substr(preg_replace('/[^a-z0-9]/', '_', strtolower($name)) ?? '', 0, 40);
}
}