Unverified Commit 662e8b20 authored by Paul Yang's avatar Paul Yang Committed by GitHub

Provide util funtions to figure out correct php class names. (#3850)

parent 1144768d
......@@ -215,19 +215,12 @@ std::string NamespacedName(const string& classname,
template <typename DescriptorType>
std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
string classname = desc->name();
const Descriptor* containing = desc->containing_type();
while (containing != NULL) {
classname = containing->name() + '_' + classname;
containing = containing->containing_type();
}
classname = ClassNamePrefix(classname, desc) + classname;
string classname = GeneratedClassName(desc);
return NamespacedName(classname, desc, is_descriptor);
}
std::string FullClassName(const ServiceDescriptor* desc, bool is_descriptor) {
string classname = desc->name();
classname = ClassNamePrefix(classname, desc) + classname;
string classname = GeneratedClassName(desc);
return NamespacedName(classname, desc, is_descriptor);
}
......@@ -1419,6 +1412,31 @@ bool Generator::Generate(const FileDescriptor* file, const string& parameter,
return true;
}
std::string GeneratedClassName(const Descriptor* desc) {
std::string classname = desc->name();
const Descriptor* containing = desc->containing_type();
while (containing != NULL) {
classname = containing->name() + '_' + classname;
containing = containing->containing_type();
}
return ClassNamePrefix(classname, desc) + classname;
}
std::string GeneratedClassName(const EnumDescriptor* desc) {
std::string classname = desc->name();
const Descriptor* containing = desc->containing_type();
while (containing != NULL) {
classname = containing->name() + '_' + classname;
containing = containing->containing_type();
}
return ClassNamePrefix(classname, desc) + classname;
}
std::string GeneratedClassName(const ServiceDescriptor* desc) {
std::string classname = desc->name();
return ClassNamePrefix(classname, desc) + classname;
}
} // namespace php
} // namespace compiler
} // namespace protobuf
......
......@@ -32,6 +32,7 @@
#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
#include <string>
......@@ -47,8 +48,16 @@ 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.
std::string GeneratedClassName(const google::protobuf::Descriptor* desc);
std::string GeneratedClassName(const google::protobuf::EnumDescriptor* desc);
std::string GeneratedClassName(const google::protobuf::ServiceDescriptor* desc);
} // namespace php
} // namespace compiler
} // namespace protobuf
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment