Skip to content

Commit

Permalink
Add support for grpc only gapic
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Apr 23, 2024
1 parent 46dc31c commit 8355a80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 1 addition & 3 deletions rules_php_gapic/php_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def php_gapic_srcjar(
# Transport.
if transport == None:
transport = "grpc+rest"
if transport == "grpc":
fail("Error: gRPC-only PHP GAPIC libraries are not yet supported")
if transport != "grpc+rest" and transport != "rest":
if transport != "grpc+rest" and transport != "rest" and transport != "grpc":
fail("Error: Only 'grpc+rest' or 'rest' transports are supported")

# Set plugin arguments.
Expand Down
18 changes: 13 additions & 5 deletions src/Generation/GapicClientV2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,23 @@ private function defaultTransport()

private function supportedTransports()
{
if ($this->serviceDetails->transportType !== Transport::REST) {
return null;
}
return AST::method('supportedTransports')
->withPhpDocText('Implements GapicClientTrait::supportedTransports.')
if ($this->serviceDetails->transportType === Transport::REST) {
return AST::method('supportedTransports')
->withPhpDocText('Implements ClientOptionsTrait::supportedTransports.')
->withAccess(Access::PRIVATE, Access::STATIC)
->withBody(AST::block(
AST::return(AST::array(['rest']))
));
}

if ($this->serviceDetails->transportType === Transport::GRPC) {
return AST::method('supportedTransports')
->withPhpDocText('Implements ClientOptionsTrait::supportedTransports.')
->withAccess(Access::PRIVATE, Access::STATIC)
->withBody(AST::block(
AST::return(AST::array(['grpc', 'grpc-fallback']))
));
}
}

private function construct(): PhpClassMember
Expand Down
1 change: 1 addition & 0 deletions src/Utils/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Transport
// supported in the future (e.g. gRPC only).
public const GRPC_REST = 1;
public const REST = 2;
public const GRPC = 3;

/**
* Returns true if the given transport string indicates that grpc+rest transports
Expand Down

0 comments on commit 8355a80

Please sign in to comment.