@@ -31,6 +31,10 @@ public function __construct(GameApi $gameApi, GameRepository $gameRepository, En
31
31
}
32
32
33
33
public function new (Request $ request ) {
34
+ if ($ request ->getMethod () == 'OPTIONS ' ) {
35
+ return new Response (Response::HTTP_OK );
36
+ }
37
+
34
38
$ body = json_decode ($ request ->getContent (), true );
35
39
$ apiResponse = $ this ->api ->new (self ::DEFAULT_SIZE , $ body ['mode ' ] === 'multi ' );
36
40
$ this ->em ->persist ($ apiResponse ['player ' ]);
@@ -43,7 +47,11 @@ public function new(Request $request) {
43
47
]);
44
48
}
45
49
46
- public function game (GameContext $ context ) {
50
+ public function game (Request $ request , GameContext $ context ) {
51
+ if ($ request ->getMethod () == 'OPTIONS ' ) {
52
+ return new Response (Response::HTTP_OK );
53
+ }
54
+
47
55
$ game = $ context ->getGame ();
48
56
$ currentPlayer = $ context ->getPlayer ();
49
57
$ player = $ currentPlayer ?: $ game ->getPlayer1 ();
@@ -71,7 +79,11 @@ public function game(GameContext $context) {
71
79
]);
72
80
}
73
81
74
- public function cancel (GameContext $ context ) {
82
+ public function cancel (Request $ request , GameContext $ context ) {
83
+ if ($ request ->getMethod () == 'OPTIONS ' ) {
84
+ return new Response (Response::HTTP_OK );
85
+ }
86
+
75
87
if ($ context ->getIsPlayer ()) {
76
88
$ this ->em ->remove ($ context ->getGame ());
77
89
$ this ->em ->flush ();
@@ -80,12 +92,14 @@ public function cancel(GameContext $context) {
80
92
Response::HTTP_OK
81
93
);
82
94
}
83
- return new Response (
84
- Response::HTTP_INTERNAL_SERVER_ERROR
85
- );
95
+ return new Response (Response::HTTP_INTERNAL_SERVER_ERROR );
86
96
}
87
97
88
- public function join (GameContext $ context , TokenGenerator $ tokenGenerator ) {
98
+ public function join (Request $ request , GameContext $ context , TokenGenerator $ tokenGenerator ) {
99
+ if ($ request ->getMethod () == 'OPTIONS ' ) {
100
+ return new Response (Response::HTTP_OK );
101
+ }
102
+
89
103
$ game = $ context ->getGame ();
90
104
91
105
if ($ game ->isFull ()) {
@@ -110,7 +124,11 @@ public function join(GameContext $context, TokenGenerator $tokenGenerator) {
110
124
]);
111
125
}
112
126
113
- public function move (GameContext $ context , int $ tile ) {
127
+ public function move (Request $ request , GameContext $ context , int $ tile ) {
128
+ if ($ request ->getMethod () == 'OPTIONS ' ) {
129
+ return new Response (Response::HTTP_OK );
130
+ }
131
+
114
132
$ game = $ context ->getGame ();
115
133
$ currentPlayer = $ context ->getPlayer ();
116
134
@@ -128,7 +146,11 @@ public function move(GameContext $context, int $tile) {
128
146
]);
129
147
}
130
148
131
- public function games () {
149
+ public function games (Request $ request ) {
150
+ if ($ request ->getMethod () == 'OPTIONS ' ) {
151
+ return new Response (Response::HTTP_OK );
152
+ }
153
+
132
154
$ gameIds = $ this ->gameRepository ->findOpenMultiplayerGames ();
133
155
134
156
return new JsonResponse ([
0 commit comments