chg: dev: replace the legacy gos/web-socket-bundle & replace it with Mercure protocol #4
This commit is contained in:
@@ -16,9 +16,10 @@ use App\Entity\PlayedGame;
|
||||
use App\Interfaces\RpcManagerInterface;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Exception;
|
||||
use JsonException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class RpcManager
|
||||
@@ -30,13 +31,12 @@ use Psr\Log\LoggerInterface;
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 09.
|
||||
*/
|
||||
class RpcManager extends WebsocketManager implements RpcManagerInterface
|
||||
class RpcManager implements RpcManagerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private LoggerInterface $logger,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getConnectInformation($params): string
|
||||
@@ -45,17 +45,33 @@ class RpcManager extends WebsocketManager implements RpcManagerInterface
|
||||
$grid = $this->getGrid($gameAssoc);
|
||||
$users = null !== $grid ? $this->getUsers($gameAssoc) : null;
|
||||
|
||||
return base64_encode(json_encode([
|
||||
'grid' => $grid,
|
||||
'users' => $users,
|
||||
], JSON_THROW_ON_ERROR, 512));
|
||||
try {
|
||||
return base64_encode(json_encode([
|
||||
'grid' => $grid,
|
||||
'users' => $users,
|
||||
], JSON_THROW_ON_ERROR, 512));
|
||||
} catch (JsonException $e) {
|
||||
throw new RuntimeException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function saveGrid($data): bool
|
||||
{
|
||||
$existingGame = $this->entityManager
|
||||
->getRepository(PlayedGame::class)
|
||||
->findOneByGameAssoc($data[1]);
|
||||
|
||||
if (null !== $existingGame) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$playedGame = new PlayedGame();
|
||||
$grid = new Grid();
|
||||
$rows = json_decode(base64_decode($data[0]), true, 512, JSON_THROW_ON_ERROR);
|
||||
try {
|
||||
$rows = json_decode(base64_decode($data[0]), true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (JsonException $e) {
|
||||
throw new RuntimeException($e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ($rows as $row) {
|
||||
@@ -66,7 +82,6 @@ class RpcManager extends WebsocketManager implements RpcManagerInterface
|
||||
/** Save Row */
|
||||
$gridRow->setGrid($grid);
|
||||
$this->entityManager->persist($gridRow);
|
||||
|
||||
}
|
||||
|
||||
/** Save Grid */
|
||||
@@ -81,8 +96,6 @@ class RpcManager extends WebsocketManager implements RpcManagerInterface
|
||||
$this->entityManager->persist($playedGame);
|
||||
|
||||
$this->entityManager->flush();
|
||||
} catch (ORMException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user