Merge pull request #4702 from TeBoring/3.6.x

Cherry-pick changes into 3.6.x
pull/4706/head v3.6.0rc2
Paul Yang 7 years ago committed by GitHub
commit a239ed2bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/google/protobuf/compiler/php/php_generator.cc
  2. 11
      src/google/protobuf/compiler/php/php_generator.h

@ -157,7 +157,7 @@ std::string ClassNamePrefix(const string& classname,
}
template <typename DescriptorType>
std::string GeneratedClassName(const DescriptorType* desc) {
std::string GeneratedClassNameImpl(const DescriptorType* desc) {
std::string classname = ClassNamePrefix(desc->name(), desc) + desc->name();
const Descriptor* containing = desc->containing_type();
while (containing != NULL) {
@ -168,11 +168,23 @@ std::string GeneratedClassName(const DescriptorType* desc) {
return classname;
}
std::string GeneratedClassName(const ServiceDescriptor* desc) {
std::string GeneratedClassNameImpl(const ServiceDescriptor* desc) {
std::string classname = desc->name();
return ClassNamePrefix(classname, desc) + classname;
}
std::string GeneratedClassName(const Descriptor* desc) {
return GeneratedClassNameImpl(desc);
}
std::string GeneratedClassName(const EnumDescriptor* desc) {
return GeneratedClassNameImpl(desc);
}
std::string GeneratedClassName(const ServiceDescriptor* desc) {
return GeneratedClassNameImpl(desc);
}
template <typename DescriptorType>
std::string LegacyGeneratedClassName(const DescriptorType* desc) {
std::string classname = desc->name();
@ -242,7 +254,7 @@ std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
template <typename DescriptorType>
std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
string classname = GeneratedClassName(desc);
string classname = GeneratedClassNameImpl(desc);
string php_namespace = RootPhpNamespace(desc, is_descriptor);
if (php_namespace != "") {
return php_namespace + "\\" + classname;
@ -1074,7 +1086,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file, const DescriptorType* d
Outdent(&printer);
printer.Print("}\n");
printer.Print("class_exists(^new^::class);\n",
"new", GeneratedClassName(desc));
"new", GeneratedClassNameImpl(desc));
printer.Print("@trigger_error('^old^ is deprecated and will be removed in "
"the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n",
"old", LegacyFullClassName(desc, is_descriptor),

@ -48,9 +48,18 @@ class LIBPROTOC_EXPORT Generator
const string& parameter,
GeneratorContext* generator_context,
string* error) const;
};
// To skip reserved keywords in php, some generated classname are prefixed.
// Other code generators may need following API to figure out the actual
// classname.
LIBPROTOC_EXPORT std::string GeneratedClassName(
const google::protobuf::Descriptor* desc);
LIBPROTOC_EXPORT std::string GeneratedClassName(
const google::protobuf::EnumDescriptor* desc);
LIBPROTOC_EXPORT std::string GeneratedClassName(
const google::protobuf::ServiceDescriptor* desc);
} // namespace php
} // namespace compiler
} // namespace protobuf

Loading…
Cancel
Save