chg: dev: increase the minimum PHP version to the latest major - and massive refactor on back-end, like Controllers and Repositories #4
This commit is contained in:
@@ -16,6 +16,8 @@ use App\Entity\PlayedGame;
|
||||
use App\Entity\Step;
|
||||
use App\Entity\User;
|
||||
use App\Interfaces\TopicManagerInterface;
|
||||
use App\Repository\PlayedGameRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use DateTimeInterface;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -37,12 +39,14 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 09.
|
||||
*/
|
||||
class TopicManager implements TopicManagerInterface
|
||||
readonly class TopicManager implements TopicManagerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly HubInterface $hub,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
private HubInterface $hub,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private LoggerInterface $logger,
|
||||
private PlayedGameRepository $playedGameRepository,
|
||||
private UserRepository $userRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -403,9 +407,7 @@ class TopicManager implements TopicManagerInterface
|
||||
|
||||
private function getPlayedGame(string $gameAssoc): ?PlayedGame
|
||||
{
|
||||
return $this->entityManager
|
||||
->getRepository(PlayedGame::class)
|
||||
->findOneByGameAssoc($gameAssoc);
|
||||
return $this->playedGameRepository->findOneByGameAssoc($gameAssoc);
|
||||
}
|
||||
|
||||
private function getPlayerCount(array $users): int
|
||||
@@ -475,9 +477,7 @@ class TopicManager implements TopicManagerInterface
|
||||
private function saveRegisteredUser(string $userName, int $count, PlayedGame $playedGame): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->entityManager
|
||||
->getRepository(User::class)
|
||||
->findOneByUsername($userName);
|
||||
$user = $this->userRepository->findOneByUsername($userName);
|
||||
|
||||
try {
|
||||
if ($count === 1) {
|
||||
@@ -524,6 +524,45 @@ class TopicManager implements TopicManagerInterface
|
||||
];
|
||||
}
|
||||
|
||||
public function publishChallenge(string $targetGameAssoc, string $challengerGameAssoc): void
|
||||
{
|
||||
$challengerGame = $this->getPlayedGame($challengerGameAssoc);
|
||||
$challengerName = 'Unknown';
|
||||
if (null !== $challengerGame) {
|
||||
$users = $this->getUserCollection($challengerGame);
|
||||
$challengerName = $users['red'] ?: $users['redAnon'] ?: $users['blue'] ?: $users['blueAnon'] ?: 'Unknown';
|
||||
}
|
||||
|
||||
try {
|
||||
$this->hub->publish(new Update(
|
||||
'mineseeker/channel/' . $targetGameAssoc,
|
||||
json_encode([
|
||||
'type' => 'challenge',
|
||||
'challengerName' => $challengerName,
|
||||
'challengerGameAssoc' => $challengerGameAssoc,
|
||||
], JSON_THROW_ON_ERROR)
|
||||
));
|
||||
} catch (JsonException $e) {
|
||||
$this->logger->error('Challenge publish error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function publishChallengeResponse(string $challengerGameAssoc, bool $accepted, string $targetGameAssoc): void
|
||||
{
|
||||
try {
|
||||
$this->hub->publish(new Update(
|
||||
'mineseeker/channel/' . $challengerGameAssoc,
|
||||
json_encode([
|
||||
'type' => 'challenge-response',
|
||||
'accepted' => $accepted,
|
||||
'targetGameAssoc' => $targetGameAssoc,
|
||||
], JSON_THROW_ON_ERROR)
|
||||
));
|
||||
} catch (JsonException $e) {
|
||||
$this->logger->error('Challenge response publish error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function publishToLobby(array $data): void
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user