diff --git a/bin/01-post-build b/bin/01-post-build new file mode 100755 index 0000000..b9f9fb5 --- /dev/null +++ b/bin/01-post-build @@ -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 diff --git a/bin/fixGoPaths b/bin/fixGoPaths deleted file mode 100755 index 1d741ee..0000000 --- a/bin/fixGoPaths +++ /dev/null @@ -1,8 +0,0 @@ -#!/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 ./go/github.com/gaming-platform/api/go/* ./go -rm -rf ./go/github.com diff --git a/bin/generateAdditionalLanguageFeatures b/bin/generateAdditionalLanguageFeatures new file mode 100755 index 0000000..284a254 --- /dev/null +++ b/bin/generateAdditionalLanguageFeatures @@ -0,0 +1,104 @@ +#!/usr/bin/env php + str_starts_with($class, PHP_PACKAGE_NAMESPACE) + && in_array(\Google\Protobuf\Internal\Message::class, class_parents($class)) + ); + $domains = []; + + foreach ($definedMessages as $message) { + preg_match( + '/(?.*)\\\\(?V\d+)\\\\(?.*)/', + 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 = '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); diff --git a/bin/generatePhpFactories b/bin/generateLegacyLanguageFeatures similarity index 96% rename from bin/generatePhpFactories rename to bin/generateLegacyLanguageFeatures index 4217342..c128251 100755 --- a/bin/generatePhpFactories +++ b/bin/generateLegacyLanguageFeatures @@ -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; diff --git a/go/chat/v1/gamingplatform.go b/go/chat/v1/gamingplatform.go new file mode 100644 index 0000000..afb83a4 --- /dev/null +++ b/go/chat/v1/gamingplatform.go @@ -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" diff --git a/go/common/v1/gamingplatform.go b/go/common/v1/gamingplatform.go new file mode 100644 index 0000000..f1c50c5 --- /dev/null +++ b/go/common/v1/gamingplatform.go @@ -0,0 +1,5 @@ +package commonv1 + +// This file is auto-generated. Do not edit! + +const ErrorResponseType = "Common.ErrorResponse.v1" diff --git a/go/identity/v1/gamingplatform.go b/go/identity/v1/gamingplatform.go new file mode 100644 index 0000000..cd96545 --- /dev/null +++ b/go/identity/v1/gamingplatform.go @@ -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" diff --git a/php/GamingPlatform/Api/Chat/V1/ChatV1.php b/php/GamingPlatform/Api/Chat/V1/ChatV1.php new file mode 100644 index 0000000..fc6d18e --- /dev/null +++ b/php/GamingPlatform/Api/Chat/V1/ChatV1.php @@ -0,0 +1,41 @@ +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; + } +} diff --git a/php/GamingPlatform/Api/Chat/V1/ChatV1Factory.php b/php/GamingPlatform/Api/Chat/V1/ChatV1Factory.php index c1320b6..5419e3b 100644 --- a/php/GamingPlatform/Api/Chat/V1/ChatV1Factory.php +++ b/php/GamingPlatform/Api/Chat/V1/ChatV1Factory.php @@ -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 { @@ -18,6 +20,7 @@ public static function createInitiateChat( return $message; } + /** @deprecated */ public static function createInitiateChatResponse( string $data ): \GamingPlatform\Api\Chat\V1\InitiateChatResponse { @@ -28,6 +31,7 @@ public static function createInitiateChatResponse( return $message; } + /** @deprecated */ public static function createMessageWritten( string $data ): \GamingPlatform\Api\Chat\V1\MessageWritten { diff --git a/php/GamingPlatform/Api/Common/V1/CommonV1.php b/php/GamingPlatform/Api/Common/V1/CommonV1.php new file mode 100644 index 0000000..681d421 --- /dev/null +++ b/php/GamingPlatform/Api/Common/V1/CommonV1.php @@ -0,0 +1,39 @@ +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; + } +} diff --git a/php/GamingPlatform/Api/Common/V1/CommonV1Factory.php b/php/GamingPlatform/Api/Common/V1/CommonV1Factory.php index 68b9c79..3a01ea5 100644 --- a/php/GamingPlatform/Api/Common/V1/CommonV1Factory.php +++ b/php/GamingPlatform/Api/Common/V1/CommonV1Factory.php @@ -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 { @@ -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 { @@ -28,6 +31,7 @@ public static function createErrorResponse_Violation( return $message; } + /** @deprecated */ public static function createErrorResponse( string $data ): \GamingPlatform\Api\Common\V1\ErrorResponse { diff --git a/php/GamingPlatform/Api/Identity/V1/IdentityV1.php b/php/GamingPlatform/Api/Identity/V1/IdentityV1.php new file mode 100644 index 0000000..d3f44a1 --- /dev/null +++ b/php/GamingPlatform/Api/Identity/V1/IdentityV1.php @@ -0,0 +1,81 @@ +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; + } +} diff --git a/php/GamingPlatform/Api/Identity/V1/IdentityV1Factory.php b/php/GamingPlatform/Api/Identity/V1/IdentityV1Factory.php index b164f73..bcf4b54 100644 --- a/php/GamingPlatform/Api/Identity/V1/IdentityV1Factory.php +++ b/php/GamingPlatform/Api/Identity/V1/IdentityV1Factory.php @@ -6,8 +6,10 @@ // This file is auto-generated. Do not edit! +/** @deprecated */ final class IdentityV1Factory { + /** @deprecated */ public static function createBot( string $data ): \GamingPlatform\Api\Identity\V1\Bot { @@ -18,6 +20,7 @@ public static function createBot( return $message; } + /** @deprecated */ public static function createGetBotByUsername( string $data ): \GamingPlatform\Api\Identity\V1\GetBotByUsername { @@ -28,6 +31,7 @@ public static function createGetBotByUsername( return $message; } + /** @deprecated */ public static function createGetBotByUsernameResponse( string $data ): \GamingPlatform\Api\Identity\V1\GetBotByUsernameResponse { @@ -38,6 +42,7 @@ public static function createGetBotByUsernameResponse( return $message; } + /** @deprecated */ public static function createRegisterBot( string $data ): \GamingPlatform\Api\Identity\V1\RegisterBot { @@ -48,6 +53,7 @@ public static function createRegisterBot( return $message; } + /** @deprecated */ public static function createRegisterBotResponse( string $data ): \GamingPlatform\Api\Identity\V1\RegisterBotResponse { @@ -58,6 +64,7 @@ public static function createRegisterBotResponse( return $message; } + /** @deprecated */ public static function createUserArrived( string $data ): \GamingPlatform\Api\Identity\V1\UserArrived { @@ -68,6 +75,7 @@ public static function createUserArrived( return $message; } + /** @deprecated */ public static function createUserSignedUp( string $data ): \GamingPlatform\Api\Identity\V1\UserSignedUp { diff --git a/project b/project index 9cca1aa..c086ad1 100755 --- a/project +++ b/project @@ -19,8 +19,7 @@ protoc() { --rm \ -v $(pwd):/project \ ghcr.io/gaming-platform/docker-php-fpm:8.3-development \ - /project/bin/generatePhpFactories - docker compose run --rm protoc /project/bin/fixGoPaths + /project/bin/01-post-build } if [ "$*" = "" ]