gs2 / gs2-php-sdk
1.4.108
2023-01-12 07:40 UTC
Requires
- php: >= 8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.4.1
Requires (Dev)
- phpunit/phpunit: ^9
- dev-master
- 1.4.108
- 1.4.107
- 1.4.106
- 1.4.105
- 1.4.104
- 1.4.103
- 1.4.102
- 1.4.101
- 1.4.100
- 1.4.97
- 1.4.96
- 1.4.95
- 1.4.91
- 1.4.90
- 1.4.89
- 1.4.88
- 1.4.87
- 1.4.86
- 1.4.85
- 1.4.84
- 1.4.83
- 1.4.82
- 1.4.81
- 1.4.80
- 1.4.79
- 1.4.78
- 1.4.77
- 1.4.76
- 1.4.75
- 1.4.74
- 1.4.73
- 1.4.72
- 1.4.71
- 1.4.70
- 1.4.69
- 1.4.68
- 1.4.67
- 1.4.66
- 1.4.65
- 1.4.64
- 1.4.63
- 1.4.62
- 1.4.61
- 1.4.60
- 1.4.59
- 1.4.58
- 1.4.57
- 1.4.56
- 1.4.55
- 1.4.54
- 1.4.53
- 1.4.52
- 1.4.50
- 1.4.49
- 1.4.48
- 1.4.47
- 1.4.46
- 1.4.45
- 1.4.43
- 1.4.42
- 1.4.41
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 0.2.0
- 0.1.1
- 0.1.0
- 0.0.1
- dev-develop
This package is auto-updated.
Last update: 2023-01-12 07:40:32 UTC
README
Game Server Services(https://gs2.io) を PHP で利用するためのSDKです。
Game Server Services とは
Game Server Services(GS2) とはモバイルゲーム開発に特化したバックエンドサーバサービス(BaaS)です。
ゲーム開発に必要なネットワーク機能をコンポーネント化してサービスとして提供します。 ゲーム内から必要な一部のコンポーネント単位で利用することができるよう設計されており、手軽に・手頃な価格で・高性能なサーバ機能を利用できます。
GS2-Document より
Getting Started
SDKを利用するには GS2 のクレデンシャルが必要です。 はじめかた の手順に従ってクレデンシャルを発行してください。
動作条件
- PHP7.1+
サンプル
GS2-Account の例
初期化処理
use Gs2\Account\Gs2AccountRestClient; use Gs2\Core\Model\BasicGs2Credential; use Gs2\Core\Model\Region; use Gs2\Core\Net\Gs2RestSession; $session = new Gs2RestSession( new BasicGs2Credential( "your client id", "your client secret" ), Region::AP_NORTHEAST_1 ); $session->open(); $client = new Gs2AccountRestClient( $session );
同期処理
use Gs2\Account\Model\ScriptSetting; use Gs2\Account\Request\CreateNamespaceRequest; use Gs2\Core\Exception\Gs2Exception; use PHPUnit\Framework\Assert; try { $result = $client->createNamespace( (new CreateNamespaceRequest()) ->withName('namespace-0001') ->withAuthenticationScript( (new ScriptSetting()) ->withTriggerScriptId('script-0001') ) ); Assert::assertNotNull($result->getItem()); Assert::assertEquals('namespace-0001', $result->getItem()->getName()); Assert::assertEquals('script-0001', $result->getItem()->getAuthenticationScript()->getTriggerScriptId()); } catch (Gs2Exception $e) { Assert::fail($e->getMessage()); }
非同期処理
use Gs2\Account\Model\ScriptSetting; use Gs2\Account\Request\CreateNamespaceRequest; use Gs2\Account\Result\CreateNamespaceResult; use Gs2\Core\Exception\Gs2Exception; use PHPUnit\Framework\Assert; // 非同期処理をハンドリングするための Promise が返る $promise = $client->createNamespaceAsync( (new CreateNamespaceRequest()) ->withName('namespace-0001') ->withAuthenticationScript( (new ScriptSetting()) ->withTriggerScriptId('script-0001') ) )->then( function (CreateNamespaceResult $result) { // コールバック形式でハンドリングしたい場合は成功時のハンドラーをここに記述 Assert::assertNotNull($result->getItem()); Assert::assertEquals('namespace-0001', $result->getItem()->getName()); Assert::assertEquals('script-0001', $result->getItem()->getAuthenticationScript()->getTriggerScriptId()); }, function (Gs2Exception $e) { // コールバック形式でハンドリングしたい場合は失敗時のハンドラーをここに記述 Assert::fail($e->getMessage()); } ); try { // Promise を wait することで処理が実行される。戻り値には成功時の結果が返り、失敗時には例外が発生する。 $result = $promise->wait(); Assert::assertNotNull($result->getItem()); Assert::assertEquals('namespace-0001', $result->getItem()->getName()); Assert::assertEquals('script-0001', $result->getItem()->getAuthenticationScript()->getTriggerScriptId()); } catch (Gs2Exception $e) { Assert::fail($e->getMessage()); }
Promise に関するドキュメントは https://github.com/guzzle/promises こちらをご確認ください。
その他のサービス・通信方式の初期化処理は ドキュメント を参照ください
フィードバック
フィードバックは GS2-Feedback にお願いします。
本プロジェクトのコードは gs2-php-sdk-core 以外は全て自動生成されているため、個別に Pull-Request を頂いても対応できません。