aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/php
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-06-05 00:10:18 -0700
committerGitHub <noreply@github.com>2017-06-05 00:10:18 -0700
commit6f325805c0bc956f927b0e2dbfb4dd8133b4ed69 (patch)
tree2f7d596b8e19933b67868d7378bb663960b75f87 /src/google/protobuf/compiler/php
parentfbaad3617fbfadafbcc653a621620a5081df64eb (diff)
downloadprotobuf-6f325805c0bc956f927b0e2dbfb4dd8133b4ed69.tar.gz
protobuf-6f325805c0bc956f927b0e2dbfb4dd8133b4ed69.tar.bz2
protobuf-6f325805c0bc956f927b0e2dbfb4dd8133b4ed69.zip
Add new file option php_namespace. (#3162)
* Add new file option php_namespace. Use this option to change the namespace of php generated classes. Default is empty. When this option is empty, the package name will be used for determining the namespace. * Uncomment commented tests * Revert gdb test change * Update csharp descriptor. * Add test for empty php_namespace.
Diffstat (limited to 'src/google/protobuf/compiler/php')
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index cbddee9e..78252817 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -145,6 +145,15 @@ std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
}
classname = ClassNamePrefix(classname, desc) + classname;
+ if (desc->file()->options().has_php_namespace()) {
+ const string& php_namespace = desc->file()->options().php_namespace();
+ if (php_namespace != "") {
+ return php_namespace + '\\' + classname;
+ } else {
+ return classname;
+ }
+ }
+
if (desc->file()->package() == "") {
return classname;
} else {
@@ -822,7 +831,14 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
- if (!file->package().empty()) {
+ if (file->options().has_php_namespace()) {
+ const string& php_namespace = file->options().php_namespace();
+ if (!php_namespace.empty()) {
+ printer.Print(
+ "namespace ^name^;\n\n",
+ "name", php_namespace);
+ }
+ } else if (!file->package().empty()) {
printer.Print(
"namespace ^name^;\n\n",
"name", fullname.substr(0, lastindex));
@@ -874,7 +890,14 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
- if (!file->package().empty()) {
+ if (file->options().has_php_namespace()) {
+ const string& php_namespace = file->options().php_namespace();
+ if (!php_namespace.empty()) {
+ printer.Print(
+ "namespace ^name^;\n\n",
+ "name", php_namespace);
+ }
+ } else if (!file->package().empty()) {
printer.Print(
"namespace ^name^;\n\n",
"name", fullname.substr(0, lastindex));