47 lines
1.1 KiB
PHP
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;
|
|
}
|
|
}
|