gigrawars-open/game-client

A PHP rest client library for GigraWars game instances

dev-main 2025-08-19 19:32 UTC

This package is auto-updated.

Last update: 2025-08-19 17:32:13 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));

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.