php_generator_helpers.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
20 #define GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
21 
22 #include <algorithm>
23 
24 #include "src/compiler/config.h"
26 
27 namespace grpc_php_generator {
28 
31  const std::string& class_suffix, bool is_server) {
32  return service->name() +
33  (class_suffix == "" ? (is_server ? "" : "Client") : class_suffix) +
34  (is_server ? "Stub" : "");
35 }
36 
37 // ReplaceAll replaces all instances of search with replace in s.
39  const std::string& replace) {
40  size_t pos = 0;
41  while ((pos = s.find(search, pos)) != std::string::npos) {
42  s.replace(pos, search.length(), replace);
43  pos += replace.length();
44  }
45  return s;
46 }
47 
51  const std::string& class_suffix, bool is_server) {
52  std::ostringstream oss;
53  if (file->options().has_php_namespace()) {
54  oss << ReplaceAll(file->options().php_namespace(), "\\", "/");
55  } else {
56  std::vector<std::string> tokens =
57  grpc_generator::tokenize(file->package(), ".");
58  for (unsigned int i = 0; i < tokens.size(); i++) {
59  oss << (i == 0 ? "" : "/")
61  }
62  }
63  return oss.str() + "/" +
64  GetPHPServiceClassname(service, class_suffix, is_server) + ".php";
65 }
66 
67 // Get leading or trailing comments in a string. Comment lines start with "// ".
68 // Leading detached comments are put in front of leading comments.
69 template <typename DescriptorType>
70 inline std::string GetPHPComments(const DescriptorType* desc,
73  "*/", "&#42;/");
74 }
75 
76 } // namespace grpc_php_generator
77 
78 #endif // GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
grpc_php_generator::GetPHPServiceClassname
std::string GetPHPServiceClassname(const grpc::protobuf::ServiceDescriptor *service, const std::string &class_suffix, bool is_server)
Definition: php_generator_helpers.h:29
grpc_php_generator::ReplaceAll
std::string ReplaceAll(std::string s, const std::string &search, const std::string &replace)
Definition: php_generator_helpers.h:38
pos
int pos
Definition: libuv/docs/code/tty-gravity/main.c:11
grpc_php_generator::GetPHPComments
std::string GetPHPComments(const DescriptorType *desc, std::string prefix)
Definition: php_generator_helpers.h:70
grpc::protobuf::FileDescriptor
GRPC_CUSTOM_FILEDESCRIPTOR FileDescriptor
Definition: include/grpcpp/impl/codegen/config_protobuf.h:85
grpc_generator::GetPrefixedComments
std::string GetPrefixedComments(const DescriptorType *desc, bool leading, const std::string &prefix)
Definition: generator_helpers.h:257
config.h
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_php_generator::GetPHPServiceFilename
std::string GetPHPServiceFilename(const grpc::protobuf::FileDescriptor *file, const grpc::protobuf::ServiceDescriptor *service, const std::string &class_suffix, bool is_server)
Definition: php_generator_helpers.h:48
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
grpc_generator::tokenize
std::vector< std::string > tokenize(const std::string &input, const std::string &delimiters)
Definition: generator_helpers.h:82
search
Definition: search.py:1
grpc_generator::CapitalizeFirstLetter
std::string CapitalizeFirstLetter(std::string s)
Definition: generator_helpers.h:102
generator_helpers.h
prefix
static const char prefix[]
Definition: head_of_line_blocking.cc:28
grpc_php_generator
Definition: src/compiler/php_generator.cc:36
desc
#define desc
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:338
service
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
Definition: ProtoMethod.h:25
grpc::protobuf::ServiceDescriptor
GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor
Definition: include/grpcpp/impl/codegen/config_protobuf.h:88
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:52