aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanley.cheung@gmail.com>2017-07-19 16:49:40 -1000
committerGravatar GitHub <noreply@github.com>2017-07-19 16:49:40 -1000
commit66cedf645dfdb1c195181d1cff289792a43854b6 (patch)
tree5df8c6c9071e872500ae3f2ef20bd40790797ffa
parent6331bcf12f0690d7dc07de5d41515985506c5058 (diff)
parent8f2a054f1706fcda1d821b4c9dea250d0cb47d29 (diff)
Merge pull request #11773 from michaelbausor/stub_param
Support parameter to change PHP generated stub suffix
-rw-r--r--src/compiler/php_generator.cc12
-rw-r--r--src/compiler/php_generator.h3
-rw-r--r--src/compiler/php_generator_helpers.h17
-rw-r--r--src/compiler/php_plugin.cc5
4 files changed, 27 insertions, 10 deletions
diff --git a/src/compiler/php_generator.cc b/src/compiler/php_generator.cc
index 6d34761fdf..38ec46e656 100644
--- a/src/compiler/php_generator.cc
+++ b/src/compiler/php_generator.cc
@@ -97,13 +97,14 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) {
}
// Prints out the service descriptor object
-void PrintService(const ServiceDescriptor *service, Printer *out) {
+void PrintService(const ServiceDescriptor *service,
+ const grpc::string &parameter, Printer *out) {
map<grpc::string, grpc::string> vars;
out->Print("/**\n");
out->Print(GetPHPComments(service, " *").c_str());
out->Print(" */\n");
- vars["name"] = service->name();
- out->Print(vars, "class $name$Client extends \\Grpc\\BaseStub {\n\n");
+ vars["name"] = GetPHPServiceClassname(service, parameter);
+ out->Print(vars, "class $name$ extends \\Grpc\\BaseStub {\n\n");
out->Indent();
out->Indent();
out->Print(
@@ -131,7 +132,8 @@ void PrintService(const ServiceDescriptor *service, Printer *out) {
}
grpc::string GenerateFile(const FileDescriptor *file,
- const ServiceDescriptor *service) {
+ const ServiceDescriptor *service,
+ const grpc::string &parameter) {
grpc::string output;
{
StringOutputStream output_stream(&output);
@@ -150,7 +152,7 @@ grpc::string GenerateFile(const FileDescriptor *file,
vars["package"] = MessageIdentifierName(file->package());
out.Print(vars, "namespace $package$;\n\n");
- PrintService(service, &out);
+ PrintService(service, parameter, &out);
}
return output;
}
diff --git a/src/compiler/php_generator.h b/src/compiler/php_generator.h
index 4518bc24f9..9a04bd33d7 100644
--- a/src/compiler/php_generator.h
+++ b/src/compiler/php_generator.h
@@ -24,7 +24,8 @@
namespace grpc_php_generator {
grpc::string GenerateFile(const grpc::protobuf::FileDescriptor *file,
- const grpc::protobuf::ServiceDescriptor *service);
+ const grpc::protobuf::ServiceDescriptor *service,
+ const grpc::string &parameter);
} // namespace grpc_php_generator
diff --git a/src/compiler/php_generator_helpers.h b/src/compiler/php_generator_helpers.h
index 3a5c08b3e6..5edebf6290 100644
--- a/src/compiler/php_generator_helpers.h
+++ b/src/compiler/php_generator_helpers.h
@@ -26,9 +26,22 @@
namespace grpc_php_generator {
+inline grpc::string GetPHPServiceClassname(
+ const grpc::protobuf::ServiceDescriptor *service,
+ const grpc::string &parameter) {
+ grpc::string suffix;
+ if (parameter == "") {
+ suffix = "Client";
+ } else {
+ suffix = parameter;
+ }
+ return service->name() + suffix;
+}
+
inline grpc::string GetPHPServiceFilename(
const grpc::protobuf::FileDescriptor *file,
- const grpc::protobuf::ServiceDescriptor *service) {
+ const grpc::protobuf::ServiceDescriptor *service,
+ const grpc::string &parameter) {
std::vector<grpc::string> tokens =
grpc_generator::tokenize(file->package(), ".");
std::ostringstream oss;
@@ -36,7 +49,7 @@ inline grpc::string GetPHPServiceFilename(
oss << (i == 0 ? "" : "/")
<< grpc_generator::CapitalizeFirstLetter(tokens[i]);
}
- return oss.str() + "/" + service->name() + "Client.php";
+ return oss.str() + "/" + GetPHPServiceClassname(service, parameter) + ".php";
}
// ReplaceAll replaces all instances of search with replace in s.
diff --git a/src/compiler/php_plugin.cc b/src/compiler/php_plugin.cc
index 7a581fd7bc..bbe91656d5 100644
--- a/src/compiler/php_plugin.cc
+++ b/src/compiler/php_plugin.cc
@@ -41,10 +41,11 @@ class PHPGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
for (int i = 0; i < file->service_count(); i++) {
- grpc::string code = GenerateFile(file, file->service(i));
+ grpc::string code = GenerateFile(file, file->service(i), parameter);
// Get output file name
- grpc::string file_name = GetPHPServiceFilename(file, file->service(i));
+ grpc::string file_name =
+ GetPHPServiceFilename(file, file->service(i), parameter);
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
context->Open(file_name));