gigrawars-open/game-client

A PHP rest client library for GigraWars game instances

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Forks: 0

pkg:composer/gigrawars-open/game-client

0.1.0 2025-10-11 19:59 UTC

This package is auto-updated.

Last update: 2025-10-11 18:00:52 UTC


README

A simple PHP client library to communicate with the GigraWars Game API. The client hides HTTP details (PSR-18/HTTPlug) and offers convenient methods for common endpoints (e.g., account/player data, planets, etc.).

Requirements

  • PHP: ^8.2
  • Composer

Installation

via composer:

composer require gigrawars-open/game-client

Quick start

<?php

use GigraWars\Open\GameClient\Client;
use GigraWars\Open\GameClient\Utils\Coordinate;
use GigraWars\Open\GameClient\Utils\GameEnvironment;

require __DIR__ . '/vendor/autoload.php';

$client = new Client();

// Set base URL – either as a string or by using predefined environments
$client->setUrl(GameEnvironment::UNI5);
// or: $client->setUrl('https://uni5.gigrawars.de');

// Authenticate via API token
$client->authenticateWithToken('MY-API-TOKEN');

// Account: Get my own data
$me = $client->account()->me();

// Account: Get all my planets
$planets = $client->account()->planets();

// Account: Get a single planet by coordinate
$planet = $client->account()->planet(Coordinate::create(1, 2, 4));

// BattleReport: Get a single battle report by ID
$report = $client->battleReport()->single('36b76947-567f-4915-8a31-ffcf90e4698d');

Using predefined game environments

$client = new Client(url: GameEnvironment::MIRAGE);
$client->authenticateWithToken('MY-API-TOKEN');
$me = $client->account()->me();

Create coordinates easily

use GigraWars\Open\GameClient\Utils\Coordinate;

$c1 = Coordinate::create(1, 2, 3);
$c2 = Coordinate::createByString('1:2:3');

var_dump($c1->isEquals($c2)); // true

Error handling

  • General client errors are thrown as GigraWars\Open\GameClient\Exception\GigraWarsGameClientException.

Example:

use GigraWars\Open\GameClient\Exception\GigraWarsGameClientException;

try {
    $client->authenticateWithToken('TOKEN');
    $me = $client->account()->me();
} catch (GigraWarsGameClientException $e) {
    // Logging, retry, user notice, etc.
    error_log($e->getMessage());
}

Development

  • Run tests:
    • vendor/bin/phpunit
  • Static analysis:
    • vendor/bin/phpstan analyse
  • Coding standards (PHP_CodeSniffer):
    • vendor/bin/phpcs

License

This project is released under the MIT License. See LICENSE.md.