Files
speedBB/app/Http/Controllers/PingController.php
tracer 8e86fcdbd9
All checks were successful
CI/CD Pipeline / deploy (push) Successful in 23s
CI/CD Pipeline / promote_stable (push) Successful in 2s
Use composer metadata as primary source for version and ping build
2026-02-24 23:26:30 +01:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Setting;
use Illuminate\Http\JsonResponse;
class PingController extends Controller
{
public function __invoke(): JsonResponse
{
$build = $this->readComposerBuild();
if ($build === null) {
$build = Setting::query()->where('key', 'build')->value('value');
}
return response()->json([
'connect' => 'ok',
'version_status' => [
'build' => $build !== null ? (int) $build : null,
],
'notification_state' => false,
]);
}
private function readComposerBuild(): ?int
{
$path = base_path('composer.json');
if (!is_file($path) || !is_readable($path)) {
return null;
}
$raw = file_get_contents($path);
if ($raw === false) {
return null;
}
$data = json_decode($raw, true);
if (!is_array($data)) {
return null;
}
$build = trim((string) ($data['build'] ?? ''));
return ctype_digit($build) ? (int) $build : null;
}
}