-
Notifications
You must be signed in to change notification settings - Fork 9
/
GameCommandController.php
57 lines (41 loc) · 1.22 KB
/
GameCommandController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Afsy\UI\Controller;
use LiteCQRS\Commanding\CommandBus;
use Rhumsaa\Uuid\Uuid;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Afsy\App\Command;
class GameCommandController
{
private $commandBus;
private $router;
public function __construct(CommandBus $commandBus, RouterInterface $router)
{
$this->commandBus = $commandBus;
$this->router = $router;
}
public function startAction()
{
$id = Uuid::uuid1();
$this->commandBus->handle(new Command\StartGameCommand($id, 2));
return $this->renderGameShow($id);
}
public function continueAction($id)
{
$id = Uuid::fromString($id);
$this->commandBus->handle(new Command\DealCardCommand($id));
return $this->renderGameShow($id);
}
public function stopAction($id)
{
$id = Uuid::fromString($id);
$this->commandBus->handle(new Command\StopDealCardCommand($id));
return $this->renderGameShow($id);
}
private function renderGameShow($gameId)
{
return new RedirectResponse(
$this->router->generate('game_show', ['id' => $gameId])
);
}
}