<?phpnamespace App\Command;use App\Chat\RoomStore;use Symfony\Component\Console\Attribute\AsCommand;use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Helper\Table;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;/** The running server of this data folder: connected members, rooms. Without one: the permanent rooms on file. */#[AsCommand('status', 'Shows the running server (members, rooms) or the saved rooms')]final class StatusCommand extends Command{ public function __construct(private readonly string $data) { parent::__construct(); } protected function execute(InputInterface $input, OutputInterface $output): int { $stats = (new StatusFile($this->data . '/status.json'))->read(); if ($stats === null) { $output->writeln('No server running with the data folder ' . $this->data . '.'); $output->writeln('Permanent rooms:'); foreach ((new RoomStore($this->data . '/rooms.json'))->load() as $room) { $output->writeln(' - ' . $room->name . ' (' . count($room->history) . ' sentences kept)'); } return Command::SUCCESS; } $output->writeln(sprintf('<info>Server running</info> (pid %d): %d connections, %d members', $stats['pid'] ?? 0, $stats['clients'] ?? 0, $stats['users'] ?? 0)); $table = new Table($output); $table->setHeaders(['Room', 'Kind', 'Members']); foreach ((array)($stats['rooms'] ?? []) as $room) { $table->addRow([$room['name'], $room['permanent'] ? 'permanent' : ($room['type'] ? 'private' : 'public'), $room['members']]); } $table->render(); return Command::SUCCESS; }}