key = $key; $this->codeEngine = $codeEngine; } public function getDatasGame(): array { $data = $this->requestApi('games/launch/' . $this->key . '/' . $this->codeEngine); $this->token = $data['token']; $data = $this->requestApi('games/init/' . $this->token); return $data['game']; } public function push(array $dataPlayer): void { if (!isset($dataPlayer['reponse'])) { $this->errors(['Votre tableau de retour doit contenir une cle "reponse"']); } $dataPlayer = base64_encode(json_encode($dataPlayer)); $data = $this->requestApi('games/push/' . $this->token . '/' . $dataPlayer); $color = $data['success_game'] ? 'green' : 'red'; echo '
' . $data['message'] . '
' . 'Le Token de ta Game : ' . $this->token . '
'; } private function requestApi(string $url): array { $data = file_get_contents(self::BASE_URL . $url); $data = json_decode($data, true); if (!$data['success']) { $this->errors($data['errors']); } assert(isset($data['data'])); return $data['data']; } private function errors($errors): void { foreach ((array) $errors as $error) { echo 'Erreur : ' . $error . '
'; } exit(); } }