https://github.com/liues1992/php-protobuf-generator
Generate php protobuf code using php
https://github.com/liues1992/php-protobuf-generator
php php-protobuf
Last synced: 6 months ago
JSON representation
Generate php protobuf code using php
- Host: GitHub
- URL: https://github.com/liues1992/php-protobuf-generator
- Owner: liues1992
- License: mit
- Created: 2018-01-04T11:34:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-30T18:01:13.000Z (over 7 years ago)
- Last Synced: 2024-08-10T10:07:58.820Z (almost 2 years ago)
- Topics: php, php-protobuf
- Language: PHP
- Homepage:
- Size: 90.8 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Introduction
Generate PHP protobuf code using PHP
`./protoc-gen.php -o build tests/test3.proto`
The generated message code is meant to work with Google protobuf's official PHP implementation:
https://github.com/google/protobuf/tree/master/php
The generated service client code is meant to work with gRpc
https://grpc.io/docs/quickstart/php.html#prerequisites
# Requirements
- Unix/Linux system
- PHP >= 7.0 and composer installed
- Only support proto3 syntax proto file
- protoc installed, version >= 3.5
# Usage
- `composer require liues1992/php-protobuf-generator`
- `./vendor/bin/protoc-gen.php --out=build --grpc_out=build tests/*.proto` or use directly as plugin:
`protoc --php-custom_out=build --plugin=protoc-gen-php-custom=./vendor/bin/protoc-gen-plugin.php \
--grpc-php_out=build --plugin=protoc-gen-grpc-php=./vendor/bin/protoc-gen-grpc-plugin.php tests/*.proto`
- See the [example](./example) folder for the generated code
### Run test
`composer test`
# TODO
- [ ] More test case
- [ ] Pack to phar
- [ ] Support proto2
- [ ] Custom generator support (write your own code generators by require this package)
# Why do I need this instead of Google's default implementation?
- Sometimes you wish to customize the generated code,
which is complicated to do if you modify google/protobuf source code(c++) and recompile the protoc binary.
Think about above situations:
- Add convenience methods in message class..
- Support proto2
- Generate custom rpc code (if you are not using gRpc or you want it to use in PHP server side)
- Some bug in Google's generated code.
```
public function setEnum($var)
{
// GPBUtil::checkEnum accepts only on param
GPBUtil::checkEnum($var, \Gary\Test\Foo_Enum::class);
$this->enum = $var;
return $this;
}
```
- Cool to generate PHP code using PHP (easy for PHP developers to join).
# How does it work
That's a secret. Find out yourself.