diff options
author | Stanley Cheung <stanleycheung@google.com> | 2017-07-20 00:59:03 -0700 |
---|---|---|
committer | Stanley Cheung <stanleycheung@google.com> | 2017-08-10 11:01:35 -0700 |
commit | 5fd85b58e6412a28e640d63d362c4b626a9d3e41 (patch) | |
tree | 6cef0a3c64fa4e8b66d391ee29a362e4dc9bf19e /src/compiler/php_generator_helpers.h | |
parent | faef8bcc6533ac5fbc6a8efa4ff964fe897f2b5c (diff) |
PHP: update codegen plugin to support php_namespace option
Diffstat (limited to 'src/compiler/php_generator_helpers.h')
-rw-r--r-- | src/compiler/php_generator_helpers.h | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/compiler/php_generator_helpers.h b/src/compiler/php_generator_helpers.h index 5edebf6290..3c886794b8 100644 --- a/src/compiler/php_generator_helpers.h +++ b/src/compiler/php_generator_helpers.h @@ -28,28 +28,8 @@ namespace grpc_php_generator { inline grpc::string GetPHPServiceClassname( const grpc::protobuf::ServiceDescriptor *service, - const grpc::string ¶meter) { - 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::string ¶meter) { - std::vector<grpc::string> tokens = - grpc_generator::tokenize(file->package(), "."); - std::ostringstream oss; - for (unsigned int i = 0; i < tokens.size(); i++) { - oss << (i == 0 ? "" : "/") - << grpc_generator::CapitalizeFirstLetter(tokens[i]); - } - return oss.str() + "/" + GetPHPServiceClassname(service, parameter) + ".php"; + const grpc::string &class_suffix) { + return service->name() + (class_suffix == "" ? "Client" : class_suffix); } // ReplaceAll replaces all instances of search with replace in s. @@ -63,6 +43,25 @@ inline grpc::string ReplaceAll(grpc::string s, const grpc::string &search, return s; } +inline grpc::string GetPHPServiceFilename( + const grpc::protobuf::FileDescriptor *file, + const grpc::protobuf::ServiceDescriptor *service, + const grpc::string &class_suffix) { + std::ostringstream oss; + if (file->options().has_php_namespace()) { + oss << ReplaceAll(file->options().php_namespace(), "\\", "/"); + } else { + std::vector<grpc::string> tokens = + grpc_generator::tokenize(file->package(), "."); + for (unsigned int i = 0; i < tokens.size(); i++) { + oss << (i == 0 ? "" : "/") + << grpc_generator::CapitalizeFirstLetter(tokens[i]); + } + } + return oss.str() + "/" + GetPHPServiceClassname(service, class_suffix) + + ".php"; +} + // 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> |