gigrawars-open / game-client
A PHP rest client library for GigraWars game instances
dev-main
2025-08-19 19:32 UTC
Requires
- php: ^8.2
- php-http/client-common: ^2.7
- php-http/discovery: ^1.0
- php-http/httplug: ^2.0
- php-http/message-factory: ^1.0
- php-http/multipart-stream-builder: ^1.4
- psr/http-client-implementation: ^1.0
- psr/http-message: ^2.0
- psr/log: ^1.0|^2.0|^3.0
- symfony/polyfill-php83: ^1.32
Requires (Dev)
- guzzlehttp/guzzle: ^7.9.2
- php-http/mock-client: ^1.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.13
- symfony/var-dumper: ^7.3
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
.