Some settings

This commit is contained in:
Frank
2026-01-03 13:16:58 +01:00
parent 0d6628e7c9
commit af61a3b920
23 changed files with 616 additions and 23 deletions

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Game\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/game/api', name: 'game_api_')]
final class GameApiController extends AbstractController
{
#[Route('/ping', name: 'ping', methods: ['GET'])]
public function ping(): JsonResponse
{
return $this->json([
'ok' => true,
'service' => 'game-api',
'ts' => date('c'),
]);
}
#[Route('/echo', name: 'echo', methods: ['POST'])]
public function echo(Request $request): JsonResponse
{
$raw = (string) $request->getContent();
$data = null;
if ($raw !== '') {
try {
/** @var array<string,mixed>|null $decoded */
$decoded = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
$data = $decoded;
} catch (\Throwable $e) {
return $this->json([
'ok' => false,
'error' => 'Invalid JSON: ' . $e->getMessage(),
], Response::HTTP_BAD_REQUEST);
}
}
return $this->json([
'ok' => true,
'received' => $data,
'ts' => date('c'),
]);
}
}