feat: wrap game in centered card, style abandon button, abandon anonymous game on login
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
39
src/EventListener/AbandonAnonymousGameOnLoginListener.php
Normal file
39
src/EventListener/AbandonAnonymousGameOnLoginListener.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Entity\Game;
|
||||
use App\Repository\GameRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
|
||||
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
|
||||
|
||||
#[AsEventListener]
|
||||
class AbandonAnonymousGameOnLoginListener
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GameRepository $gameRepository,
|
||||
private readonly EntityManagerInterface $em,
|
||||
) {}
|
||||
|
||||
public function __invoke(LoginSuccessEvent $event): void
|
||||
{
|
||||
$session = $event->getRequest()->getSession();
|
||||
$gameId = $session->get('current_game_id');
|
||||
|
||||
if (!$gameId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$game = $this->gameRepository->find($gameId);
|
||||
|
||||
if ($game && $game->getStatus() === Game::STATUS_IN_PROGRESS) {
|
||||
$game->abandon();
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
$session->remove('current_game_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user