In the previous PHP grpc generator (dr slump) it was possible to add a prefix to the namespace of the generated classes via an option in the proto files called namespace. Is this possible in the new official generator? I can't find docs on how to use it.
I use it to avoid naming conflicts with generated code and user facing code in a library.
If not, is there any way (outside of search replace on generated code) to do this with protoc?
The recommended way is to use package in proto file.
On Mon, Feb 20, 2017 at 18:21 tbillington notifications@github.com wrote:
In the previous PHP grpc generator (dr slump) it was possible to add a
prefix to the namespace of the generated classes via an option in the proto
files called namespace
http://drslump.github.io/Protobuf-PHP/protobuf-php.5.html. Is this
possible in the new official generator? I can't find docs on how to use it.I use it to avoid naming conflicts with generated code and user facing
code in a library.If not, is there any way (outside of search replace on generated code) to
do this with protoc?Related: grpc/grpc#9278 https://github.com/grpc/grpc/issues/9278
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/protobuf/issues/2741, or mute the thread
https://github.com/notifications/unsubscribe-auth/AE9H5SDkarBcV1FZBTPQTvdZrTM_Ocv6ks5rekoZgaJpZM4MGzYk
.
The issue is that there's not an easy way to submodule/subpackage or anything in php/composer land. I can't just put it in a different directory and get namespace separation with the rest of the library. I could search replace the root of the namespace on the generated code but that's quite ugly.
If I change the package in proto for php it will then break when it tries to communicate with other languages running the proto who have the original package.
Any ideas on how to do this 😛 ?
Basically, if my php library is called Foo, and the proto package starts with Foo, then the generated proto is basically surface/top level namespace in my library.
I think you can generate all proto files into a "generated" foler. In your composer file, you can add mapping from the root namespace to "generated": https://getcomposer.org/doc/04-schema.md#psr-4
"":"generated"
Feel free to reopen the issue if it's not solved.
+1 Please add a prefix feature. We generate client code for java and go, which have options for each language's respective namespacing/packaging scheme. We're in a situation now where it's necessary to modify each protobuf's package value just to suit code generation for PHP.
@mkaminski1988 seems it was implemented in grpc 1.6 https://github.com/grpc/grpc/releases/tag/v1.6.0
Most helpful comment
@mkaminski1988 seems it was implemented in grpc 1.6 https://github.com/grpc/grpc/releases/tag/v1.6.0