Merge pull request #11773 from michaelbausor/stub_param

Support parameter to change PHP generated stub suffix
pull/11890/head
Stanley Cheung 8 years ago committed by GitHub
commit 66cedf645d
  1. 12
      src/compiler/php_generator.cc
  2. 3
      src/compiler/php_generator.h
  3. 17
      src/compiler/php_generator_helpers.h
  4. 5
      src/compiler/php_plugin.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;
}

@ -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

@ -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.

@ -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));

Loading…
Cancel
Save