diff options
author | Stanley Cheung <stanley.cheung@gmail.com> | 2017-06-26 08:16:25 -1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-26 08:16:25 -1000 |
commit | fdf30af6e0c0be9a51fd3ede2244e12168c59427 (patch) | |
tree | ae082f68945c44d7fbe31e14dfed6e1ad5ef011a | |
parent | 8399ff6a176126f68f4febea08c5866498a52d51 (diff) | |
parent | 495e9ac023d8ae565d8f7069799e88a79f25b21a (diff) |
Merge pull request #11524 from michaelbausor/php-protoc-plugin
Update PHP protoc plugin generation
-rw-r--r-- | src/compiler/php_generator.cc | 40 | ||||
-rw-r--r-- | src/compiler/php_generator_helpers.h | 14 |
2 files changed, 36 insertions, 18 deletions
diff --git a/src/compiler/php_generator.cc b/src/compiler/php_generator.cc index a7387d7223..6d34761fdf 100644 --- a/src/compiler/php_generator.cc +++ b/src/compiler/php_generator.cc @@ -52,14 +52,16 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) { vars["input_type_id"] = MessageIdentifierName(input_type->full_name()); vars["output_type_id"] = MessageIdentifierName(output_type->full_name()); - out->Print(GetPHPComments(method, " //").c_str()); + out->Print("/**\n"); + out->Print(GetPHPComments(method, " *").c_str()); if (method->client_streaming()) { out->Print(vars, - " // @param array $$metadata metadata\n" - " // @param array $$options call options\n" + " * @param array $$metadata metadata\n" + " * @param array $$options call options\n */\n" "public function $name$($$metadata = [], " "$$options = []) {\n"); out->Indent(); + out->Indent(); if (method->server_streaming()) { out->Print("return $$this->_bidiRequest("); } else { @@ -71,12 +73,13 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) { "$$metadata, $$options);\n"); } else { out->Print(vars, - " // @param \\$input_type_id$ $$argument input argument\n" - " // @param array $$metadata metadata\n" - " // @param array $$options call options\n" + " * @param \\$input_type_id$ $$argument input argument\n" + " * @param array $$metadata metadata\n" + " * @param array $$options call options\n */\n" "public function $name$(\\$input_type_id$ $$argument,\n" " $$metadata = [], $$options = []) {\n"); out->Indent(); + out->Indent(); if (method->server_streaming()) { out->Print("return $$this->_serverStreamRequest("); } else { @@ -89,26 +92,32 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) { "$$metadata, $$options);\n"); } out->Outdent(); + out->Outdent(); out->Print("}\n\n"); } // Prints out the service descriptor object void PrintService(const ServiceDescriptor *service, Printer *out) { map<grpc::string, grpc::string> vars; - out->Print(GetPHPComments(service, "//").c_str()); + 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"); out->Indent(); + out->Indent(); out->Print( - " // @param string $$hostname hostname\n" - " // @param array $$opts channel options\n" - " // @param \\Grpc\\Channel $$channel (optional) re-use channel " - "object\n" + "/**\n * @param string $$hostname hostname\n" + " * @param array $$opts channel options\n" + " * @param \\Grpc\\Channel $$channel (optional) re-use channel " + "object\n */\n" "public function __construct($$hostname, $$opts, " "$$channel = null) {\n"); out->Indent(); + out->Indent(); out->Print("parent::__construct($$hostname, $$opts, $$channel);\n"); out->Outdent(); + out->Outdent(); out->Print("}\n\n"); for (int i = 0; i < service->method_count(); i++) { grpc::string method_name = @@ -116,7 +125,8 @@ void PrintService(const ServiceDescriptor *service, Printer *out) { PrintMethod(service->method(i), out); } out->Outdent(); - out->Print("}\n\n"); + out->Outdent(); + out->Print("}\n"); } } @@ -138,13 +148,9 @@ grpc::string GenerateFile(const FileDescriptor *file, map<grpc::string, grpc::string> vars; vars["package"] = MessageIdentifierName(file->package()); - out.Print(vars, "namespace $package$ {\n\n"); - out.Indent(); + out.Print(vars, "namespace $package$;\n\n"); PrintService(service, &out); - - out.Outdent(); - out.Print("}\n"); } return output; } diff --git a/src/compiler/php_generator_helpers.h b/src/compiler/php_generator_helpers.h index 8e35809357..3a5c08b3e6 100644 --- a/src/compiler/php_generator_helpers.h +++ b/src/compiler/php_generator_helpers.h @@ -39,12 +39,24 @@ inline grpc::string GetPHPServiceFilename( return oss.str() + "/" + service->name() + "Client.php"; } +// ReplaceAll replaces all instances of search with replace in s. +inline grpc::string ReplaceAll(grpc::string s, const grpc::string &search, + const grpc::string &replace) { + size_t pos = 0; + while ((pos = s.find(search, pos)) != grpc::string::npos) { + s.replace(pos, search.length(), replace); + pos += replace.length(); + } + return s; +} + // Get leading or trailing comments in a string. Comment lines start with "// ". // Leading detached comments are put in in front of leading comments. template <typename DescriptorType> inline grpc::string GetPHPComments(const DescriptorType *desc, grpc::string prefix) { - return grpc_generator::GetPrefixedComments(desc, true, prefix); + return ReplaceAll(grpc_generator::GetPrefixedComments(desc, true, prefix), + "*/", "*/"); } } // namespace grpc_php_generator |