Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/01-post-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

# Go files are generated into their full module path.
# This script moves the files to the correct location.
cp -r /project/go/github.com/gaming-platform/api/go/* /project/go
rm -rf /project/go/github.com

/project/bin/generateAdditionalLanguageFeatures
/project/bin/generateLegacyLanguageFeatures
8 changes: 0 additions & 8 deletions bin/fixGoPaths

This file was deleted.

104 changes: 104 additions & 0 deletions bin/generateAdditionalLanguageFeatures
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

const PHP_PACKAGE_NAMESPACE = 'GamingPlatform\\Api';
const PHP_PACKAGE_PATH = '/project/php/GamingPlatform/Api';
const GO_PACKAGE_PATH = '/project/go';

function loadFiles($directory): void
{
$entries = array_diff(scandir($directory), ['.', '..']);
foreach ($entries as $entry) {
$path = $directory . '/' . $entry;
is_dir($path) ? loadFiles($path) : require_once $path;
}
}

function findMessagesClasses(): array
{
$definedMessages = array_filter(
get_declared_classes(),
static fn(string $class) => str_starts_with($class, PHP_PACKAGE_NAMESPACE)
&& in_array(\Google\Protobuf\Internal\Message::class, class_parents($class))
);
$domains = [];

foreach ($definedMessages as $message) {
preg_match(
'/(?<domain>.*)\\\\(?<version>V\d+)\\\\(?<message>.*)/',
substr($message, strlen(PHP_PACKAGE_NAMESPACE) + 1),
$matches
);

$domainKey = $matches['domain'] . $matches['version'];
$domains[$domainKey] ??= ['name' => $matches['domain'], 'version' => $matches['version'], 'messages' => []];
$domains[$domainKey]['messages'][] = [
'name' => $matches['message'],
'snakeName' => str_replace('\\', '_', $matches['message']),
'wireType' => !str_contains($matches['message'], '\\')
? $matches['domain'] . '.' . $matches['message'] . '.' . strtolower($matches['version'])
: null
];
}

return $domains;
}

function writePhpFiles(array $domains): void
{
foreach ($domains as $domain) {
$path = PHP_PACKAGE_PATH . '/' . $domain['name'] . '/' . $domain['version'] . '/' . $domain['name'] . $domain['version'] . '.php';
$namespace = PHP_PACKAGE_NAMESPACE . '\\' . $domain['name'] . '\\' . $domain['version'];

$content = '<?php' . PHP_EOL . PHP_EOL;
$content .= 'declare(strict_types=1);' . PHP_EOL . PHP_EOL;
$content .= 'namespace ' . $namespace . ';' . PHP_EOL . PHP_EOL;
$content .= '// This file is auto-generated. Do not edit!' . PHP_EOL . PHP_EOL;
$content .= 'final class ' . $domain['name'] . $domain['version'] . PHP_EOL;
$content .= '{' . PHP_EOL;
foreach ($domain['messages'] as $message) {
if ($message['wireType']) {
$content .= ' public const string ' . $message['name'] . 'Type = \'' . $message['wireType'] . '\';' . PHP_EOL;
}
$content .= ' public static function create' . $message['snakeName'] . '(' . PHP_EOL;
$content .= ' ?string $data = null' . PHP_EOL;
$content .= ' ): ' . $message['name'] . ' {' . PHP_EOL;
$content .= ' static $template;' . PHP_EOL;
$content .= ' $template ??= new ' . $message['name'] . '();' . PHP_EOL;
$content .= ' $message = clone $template;' . PHP_EOL;
$content .= ' if ($data !== null) $message->mergeFromString($data);' . PHP_EOL;
$content .= ' return $message;' . PHP_EOL;
$content .= ' }' . PHP_EOL;
}
$content .= '}' . PHP_EOL;

echo 'Write ' . $path . PHP_EOL;
file_put_contents($path, $content);
}
}

function writeGoFiles(array $domains): void
{
foreach ($domains as $domain) {
$path = GO_PACKAGE_PATH . '/' . strtolower($domain['name'] . '/' . $domain['version']) . '/gamingplatform.go';

$content = 'package ' . strtolower($domain['name'] . $domain['version']) . PHP_EOL . PHP_EOL;
$content .= '// This file is auto-generated. Do not edit!' . PHP_EOL . PHP_EOL;
foreach ($domain['messages'] as $message) {
if ($message['wireType']) {
$content .= 'const ' . $message['name'] . 'Type = "' . $message['wireType'] . '"' . PHP_EOL;
}
}

echo 'Write ' . $path . PHP_EOL;
file_put_contents($path, $content);
}
}

loadFiles(PHP_PACKAGE_PATH);

$messageClasses = findMessagesClasses();
writePhpFiles($messageClasses);
writeGoFiles($messageClasses);
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ function writeFactories(array $factories): void
$content .= 'declare(strict_types=1);' . PHP_EOL . PHP_EOL;
$content .= 'namespace ' . $factory['namespace'] . ';' . PHP_EOL . PHP_EOL;
$content .= '// This file is auto-generated. Do not edit!' . PHP_EOL . PHP_EOL;
$content .= '/** @deprecated */' . PHP_EOL;
$content .= 'final class ' . $factory['name'] . PHP_EOL;
$content .= '{' . PHP_EOL;
foreach ($factory['methods'] as $method) {
$content .= ' /** @deprecated */' . PHP_EOL;
$content .= ' public static function ' . $method['name'] . '(' . PHP_EOL;
$content .= ' string $data' . PHP_EOL;
$content .= ' ): ' . $method['returnType'] . ' {' . PHP_EOL;
Expand Down
7 changes: 7 additions & 0 deletions go/chat/v1/gamingplatform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package chatv1

// This file is auto-generated. Do not edit!

const InitiateChatType = "Chat.InitiateChat.v1"
const InitiateChatResponseType = "Chat.InitiateChatResponse.v1"
const MessageWrittenType = "Chat.MessageWritten.v1"
5 changes: 5 additions & 0 deletions go/common/v1/gamingplatform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package commonv1

// This file is auto-generated. Do not edit!

const ErrorResponseType = "Common.ErrorResponse.v1"
11 changes: 11 additions & 0 deletions go/identity/v1/gamingplatform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package identityv1

// This file is auto-generated. Do not edit!

const BotType = "Identity.Bot.v1"
const GetBotByUsernameType = "Identity.GetBotByUsername.v1"
const GetBotByUsernameResponseType = "Identity.GetBotByUsernameResponse.v1"
const RegisterBotType = "Identity.RegisterBot.v1"
const RegisterBotResponseType = "Identity.RegisterBotResponse.v1"
const UserArrivedType = "Identity.UserArrived.v1"
const UserSignedUpType = "Identity.UserSignedUp.v1"
41 changes: 41 additions & 0 deletions php/GamingPlatform/Api/Chat/V1/ChatV1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace GamingPlatform\Api\Chat\V1;

// This file is auto-generated. Do not edit!

final class ChatV1
{
public const string InitiateChatType = 'Chat.InitiateChat.v1';
public static function createInitiateChat(
?string $data = null
): InitiateChat {
static $template;
$template ??= new InitiateChat();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string InitiateChatResponseType = 'Chat.InitiateChatResponse.v1';
public static function createInitiateChatResponse(
?string $data = null
): InitiateChatResponse {
static $template;
$template ??= new InitiateChatResponse();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string MessageWrittenType = 'Chat.MessageWritten.v1';
public static function createMessageWritten(
?string $data = null
): MessageWritten {
static $template;
$template ??= new MessageWritten();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
}
4 changes: 4 additions & 0 deletions php/GamingPlatform/Api/Chat/V1/ChatV1Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

// This file is auto-generated. Do not edit!

/** @deprecated */
final class ChatV1Factory
{
/** @deprecated */
public static function createInitiateChat(
string $data
): \GamingPlatform\Api\Chat\V1\InitiateChat {
Expand All @@ -18,6 +20,7 @@ public static function createInitiateChat(
return $message;
}

/** @deprecated */
public static function createInitiateChatResponse(
string $data
): \GamingPlatform\Api\Chat\V1\InitiateChatResponse {
Expand All @@ -28,6 +31,7 @@ public static function createInitiateChatResponse(
return $message;
}

/** @deprecated */
public static function createMessageWritten(
string $data
): \GamingPlatform\Api\Chat\V1\MessageWritten {
Expand Down
39 changes: 39 additions & 0 deletions php/GamingPlatform/Api/Common/V1/CommonV1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace GamingPlatform\Api\Common\V1;

// This file is auto-generated. Do not edit!

final class CommonV1
{
public static function createErrorResponse_Violation_Parameter(
?string $data = null
): ErrorResponse\Violation\Parameter {
static $template;
$template ??= new ErrorResponse\Violation\Parameter();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public static function createErrorResponse_Violation(
?string $data = null
): ErrorResponse\Violation {
static $template;
$template ??= new ErrorResponse\Violation();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string ErrorResponseType = 'Common.ErrorResponse.v1';
public static function createErrorResponse(
?string $data = null
): ErrorResponse {
static $template;
$template ??= new ErrorResponse();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
}
4 changes: 4 additions & 0 deletions php/GamingPlatform/Api/Common/V1/CommonV1Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

// This file is auto-generated. Do not edit!

/** @deprecated */
final class CommonV1Factory
{
/** @deprecated */
public static function createErrorResponse_Violation_Parameter(
string $data
): \GamingPlatform\Api\Common\V1\ErrorResponse\Violation\Parameter {
Expand All @@ -18,6 +20,7 @@ public static function createErrorResponse_Violation_Parameter(
return $message;
}

/** @deprecated */
public static function createErrorResponse_Violation(
string $data
): \GamingPlatform\Api\Common\V1\ErrorResponse\Violation {
Expand All @@ -28,6 +31,7 @@ public static function createErrorResponse_Violation(
return $message;
}

/** @deprecated */
public static function createErrorResponse(
string $data
): \GamingPlatform\Api\Common\V1\ErrorResponse {
Expand Down
81 changes: 81 additions & 0 deletions php/GamingPlatform/Api/Identity/V1/IdentityV1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace GamingPlatform\Api\Identity\V1;

// This file is auto-generated. Do not edit!

final class IdentityV1
{
public const string BotType = 'Identity.Bot.v1';
public static function createBot(
?string $data = null
): Bot {
static $template;
$template ??= new Bot();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string GetBotByUsernameType = 'Identity.GetBotByUsername.v1';
public static function createGetBotByUsername(
?string $data = null
): GetBotByUsername {
static $template;
$template ??= new GetBotByUsername();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string GetBotByUsernameResponseType = 'Identity.GetBotByUsernameResponse.v1';
public static function createGetBotByUsernameResponse(
?string $data = null
): GetBotByUsernameResponse {
static $template;
$template ??= new GetBotByUsernameResponse();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string RegisterBotType = 'Identity.RegisterBot.v1';
public static function createRegisterBot(
?string $data = null
): RegisterBot {
static $template;
$template ??= new RegisterBot();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string RegisterBotResponseType = 'Identity.RegisterBotResponse.v1';
public static function createRegisterBotResponse(
?string $data = null
): RegisterBotResponse {
static $template;
$template ??= new RegisterBotResponse();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string UserArrivedType = 'Identity.UserArrived.v1';
public static function createUserArrived(
?string $data = null
): UserArrived {
static $template;
$template ??= new UserArrived();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
public const string UserSignedUpType = 'Identity.UserSignedUp.v1';
public static function createUserSignedUp(
?string $data = null
): UserSignedUp {
static $template;
$template ??= new UserSignedUp();
$message = clone $template;
if ($data !== null) $message->mergeFromString($data);
return $message;
}
}
Loading
Loading