Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ltd-beget/php-grpc-client-generator


https://github.com/ltd-beget/php-grpc-client-generator

grpc php protobuf

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# Php GRPC client generator

This util generate wrappers for client classes generated by `protoc-gen-php`.

Proto file example
------------------

```
syntax = "proto3";

package beget.hello;

service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
string name = 1;
}

message HelloReply {
string message = 1;
}

```

Usage
-----

```
protoc-gen-php -Dmultifile -i ../protos/ -o . ../protos/hello.proto
```

```
ini_set('xdebug.max_nesting_level', 3000);

use LTDBeget\util\PhpGrpcClientGenerator\PhpGenerator;

(new PhpGenerator())
->setInputPath(__DIR__ . '/proto')
->setOutputPath(__DIR__)
->run();

```

```
require __DIR__ . '/vendor/autoload.php';

$client = new \beget\hello\GreeterClientSimple(
new \beget\hello\GreeterClient(
'localhost:50051',
[
'credentials' => Grpc\ChannelCredentials::createInsecure(),
]
)
);

$request = new \beget\hello\HelloRequest();
$request->setName(time());

$reply = $client->SayHello($request);

echo $reply->getMessage(), PHP_EOL;
```