From 6f325805c0bc956f927b0e2dbfb4dd8133b4ed69 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 5 Jun 2017 00:10:18 -0700 Subject: 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. --- .../Google/Protobuf/Internal/DescriptorProto.php | 20 ++++++ .../Internal/DescriptorProto_ExtensionRange.php | 4 ++ .../Internal/DescriptorProto_ReservedRange.php | 4 ++ .../Protobuf/Internal/EnumDescriptorProto.php | 6 ++ php/src/Google/Protobuf/Internal/EnumOptions.php | 6 ++ .../Protobuf/Internal/EnumValueDescriptorProto.php | 6 ++ .../Google/Protobuf/Internal/EnumValueOptions.php | 4 ++ .../Protobuf/Internal/FieldDescriptorProto.php | 20 ++++++ php/src/Google/Protobuf/Internal/FieldOptions.php | 14 ++++ .../Protobuf/Internal/FileDescriptorProto.php | 24 +++++++ .../Google/Protobuf/Internal/FileDescriptorSet.php | 2 + php/src/Google/Protobuf/Internal/FileOptions.php | 82 ++++++++++++++++++++++ .../Google/Protobuf/Internal/GeneratedCodeInfo.php | 2 + .../Internal/GeneratedCodeInfo_Annotation.php | 8 +++ .../Google/Protobuf/Internal/MessageOptions.php | 10 +++ .../Protobuf/Internal/MethodDescriptorProto.php | 12 ++++ php/src/Google/Protobuf/Internal/MethodOptions.php | 6 ++ .../Protobuf/Internal/OneofDescriptorProto.php | 4 ++ php/src/Google/Protobuf/Internal/OneofOptions.php | 2 + .../Protobuf/Internal/ServiceDescriptorProto.php | 6 ++ .../Google/Protobuf/Internal/ServiceOptions.php | 4 ++ .../Google/Protobuf/Internal/SourceCodeInfo.php | 2 + .../Protobuf/Internal/SourceCodeInfo_Location.php | 10 +++ .../Protobuf/Internal/UninterpretedOption.php | 14 ++++ .../Internal/UninterpretedOption_NamePart.php | 4 ++ php/src/Google/Protobuf/descriptor.php | 13 ++++ 26 files changed, 289 insertions(+) (limited to 'php/src/Google/Protobuf') diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php index 948c5876..c72c0962 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php @@ -97,6 +97,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -120,6 +122,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->field = $arr; $this->has_field = true; + + return $this; } public function hasField() @@ -143,6 +147,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->extension = $arr; $this->has_extension = true; + + return $this; } public function hasExtension() @@ -166,6 +172,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $this->nested_type = $arr; $this->has_nested_type = true; + + return $this; } public function hasNestedType() @@ -189,6 +197,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $this->enum_type = $arr; $this->has_enum_type = true; + + return $this; } public function hasEnumType() @@ -212,6 +222,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class); $this->extension_range = $arr; $this->has_extension_range = true; + + return $this; } public function hasExtensionRange() @@ -235,6 +247,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class); $this->oneof_decl = $arr; $this->has_oneof_decl = true; + + return $this; } public function hasOneofDecl() @@ -258,6 +272,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() @@ -281,6 +297,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class); $this->reserved_range = $arr; $this->has_reserved_range = true; + + return $this; } public function hasReservedRange() @@ -314,6 +332,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->reserved_name = $arr; $this->has_reserved_name = true; + + return $this; } public function hasReservedName() diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php index 738a1738..b5e5453e 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php @@ -48,6 +48,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->start = $var; $this->has_start = true; + + return $this; } public function hasStart() @@ -71,6 +73,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->end = $var; $this->has_end = true; + + return $this; } public function hasEnd() diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php index be36b8aa..e5b7b05a 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php @@ -70,6 +70,8 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->start = $var; $this->has_start = true; + + return $this; } public function hasStart() @@ -101,6 +103,8 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->end = $var; $this->has_end = true; + + return $this; } public function hasEnd() diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php index 73f6edbd..bf597436 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -57,6 +57,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -80,6 +82,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class); $this->value = $arr; $this->has_value = true; + + return $this; } public function hasValue() @@ -103,6 +107,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/EnumOptions.php b/php/src/Google/Protobuf/Internal/EnumOptions.php index 4fa0bce7..cfa0cb3e 100644 --- a/php/src/Google/Protobuf/Internal/EnumOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumOptions.php @@ -79,6 +79,8 @@ class EnumOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->allow_alias = $var; $this->has_allow_alias = true; + + return $this; } public function hasAllowAlias() @@ -116,6 +118,8 @@ class EnumOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -147,6 +151,8 @@ class EnumOptions extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php index 94dc36ec..43eee73f 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -57,6 +57,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -80,6 +82,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->number = $var; $this->has_number = true; + + return $this; } public function hasNumber() @@ -103,6 +107,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/EnumValueOptions.php b/php/src/Google/Protobuf/Internal/EnumValueOptions.php index 232a6738..d66c7684 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumValueOptions.php @@ -73,6 +73,8 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -104,6 +106,8 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php index 6ae2cd41..2af9c0a0 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -130,6 +130,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -153,6 +155,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->number = $var; $this->has_number = true; + + return $this; } public function hasNumber() @@ -176,6 +180,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class); $this->label = $var; $this->has_label = true; + + return $this; } public function hasLabel() @@ -209,6 +215,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class); $this->type = $var; $this->has_type = true; + + return $this; } public function hasType() @@ -248,6 +256,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->type_name = $var; $this->has_type_name = true; + + return $this; } public function hasTypeName() @@ -281,6 +291,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->extendee = $var; $this->has_extendee = true; + + return $this; } public function hasExtendee() @@ -320,6 +332,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->default_value = $var; $this->has_default_value = true; + + return $this; } public function hasDefaultValue() @@ -353,6 +367,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkInt32($var); $this->oneof_index = $var; $this->has_oneof_index = true; + + return $this; } public function hasOneofIndex() @@ -390,6 +406,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->json_name = $var; $this->has_json_name = true; + + return $this; } public function hasJsonName() @@ -413,6 +431,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/FieldOptions.php b/php/src/Google/Protobuf/Internal/FieldOptions.php index 8db7ed67..b30caa75 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions.php @@ -156,6 +156,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_CType::class); $this->ctype = $var; $this->has_ctype = true; + + return $this; } public function hasCtype() @@ -195,6 +197,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->packed = $var; $this->has_packed = true; + + return $this; } public function hasPacked() @@ -242,6 +246,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_JSType::class); $this->jstype = $var; $this->has_jstype = true; + + return $this; } public function hasJstype() @@ -319,6 +325,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->lazy = $var; $this->has_lazy = true; + + return $this; } public function hasLazy() @@ -356,6 +364,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -387,6 +397,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message GPBUtil::checkBool($var); $this->weak = $var; $this->has_weak = true; + + return $this; } public function hasWeak() @@ -418,6 +430,8 @@ class FieldOptions extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php index 0363d9e9..b229522a 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -147,6 +147,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -178,6 +180,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->package = $var; $this->has_package = true; + + return $this; } public function hasPackage() @@ -209,6 +213,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->dependency = $arr; $this->has_dependency = true; + + return $this; } public function hasDependency() @@ -240,6 +246,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->public_dependency = $arr; $this->has_public_dependency = true; + + return $this; } public function hasPublicDependency() @@ -273,6 +281,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->weak_dependency = $arr; $this->has_weak_dependency = true; + + return $this; } public function hasWeakDependency() @@ -304,6 +314,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $this->message_type = $arr; $this->has_message_type = true; + + return $this; } public function hasMessageType() @@ -327,6 +339,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $this->enum_type = $arr; $this->has_enum_type = true; + + return $this; } public function hasEnumType() @@ -350,6 +364,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class); $this->service = $arr; $this->has_service = true; + + return $this; } public function hasService() @@ -373,6 +389,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->extension = $arr; $this->has_extension = true; + + return $this; } public function hasExtension() @@ -396,6 +414,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() @@ -433,6 +453,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class); $this->source_code_info = $var; $this->has_source_code_info = true; + + return $this; } public function hasSourceCodeInfo() @@ -466,6 +488,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message GPBUtil::checkString($var, True); $this->syntax = $var; $this->has_syntax = true; + + return $this; } public function hasSyntax() diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php index 0bcc8051..8271ee66 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php @@ -48,6 +48,8 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class); $this->file = $arr; $this->has_file = true; + + return $this; } public function hasFile() diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php index 22653a4f..332da3dc 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -186,6 +186,17 @@ class FileOptions extends \Google\Protobuf\Internal\Message */ private $php_class_prefix = ''; private $has_php_class_prefix = false; + /** + *
+     * 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.
+     * 
+ * + * optional string php_namespace = 41; + */ + private $php_namespace = ''; + private $has_php_namespace = false; /** *
      * The parser stores options it doesn't recognize here. See above.
@@ -231,6 +242,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->java_package = $var;
         $this->has_java_package = true;
+
+        return $this;
     }
 
     public function hasJavaPackage()
@@ -270,6 +283,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->java_outer_classname = $var;
         $this->has_java_outer_classname = true;
+
+        return $this;
     }
 
     public function hasJavaOuterClassname()
@@ -311,6 +326,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->java_multiple_files = $var;
         $this->has_java_multiple_files = true;
+
+        return $this;
     }
 
     public function hasJavaMultipleFiles()
@@ -342,6 +359,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->java_generate_equals_and_hash = $var;
         $this->has_java_generate_equals_and_hash = true;
+
+        return $this;
     }
 
     public function hasJavaGenerateEqualsAndHash()
@@ -383,6 +402,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->java_string_check_utf8 = $var;
         $this->has_java_string_check_utf8 = true;
+
+        return $this;
     }
 
     public function hasJavaStringCheckUtf8()
@@ -406,6 +427,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class);
         $this->optimize_for = $var;
         $this->has_optimize_for = true;
+
+        return $this;
     }
 
     public function hasOptimizeFor()
@@ -445,6 +468,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->go_package = $var;
         $this->has_go_package = true;
+
+        return $this;
     }
 
     public function hasGoPackage()
@@ -492,6 +517,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->cc_generic_services = $var;
         $this->has_cc_generic_services = true;
+
+        return $this;
     }
 
     public function hasCcGenericServices()
@@ -515,6 +542,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->java_generic_services = $var;
         $this->has_java_generic_services = true;
+
+        return $this;
     }
 
     public function hasJavaGenericServices()
@@ -538,6 +567,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->py_generic_services = $var;
         $this->has_py_generic_services = true;
+
+        return $this;
     }
 
     public function hasPyGenericServices()
@@ -575,6 +606,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->deprecated = $var;
         $this->has_deprecated = true;
+
+        return $this;
     }
 
     public function hasDeprecated()
@@ -608,6 +641,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->cc_enable_arenas = $var;
         $this->has_cc_enable_arenas = true;
+
+        return $this;
     }
 
     public function hasCcEnableArenas()
@@ -641,6 +676,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->objc_class_prefix = $var;
         $this->has_objc_class_prefix = true;
+
+        return $this;
     }
 
     public function hasObjcClassPrefix()
@@ -672,6 +709,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->csharp_namespace = $var;
         $this->has_csharp_namespace = true;
+
+        return $this;
     }
 
     public function hasCsharpNamespace()
@@ -709,6 +748,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->swift_prefix = $var;
         $this->has_swift_prefix = true;
+
+        return $this;
     }
 
     public function hasSwiftPrefix()
@@ -742,6 +783,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->php_class_prefix = $var;
         $this->has_php_class_prefix = true;
+
+        return $this;
     }
 
     public function hasPhpClassPrefix()
@@ -749,6 +792,43 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         return $this->has_php_class_prefix;
     }
 
+    /**
+     * 
+     * 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.
+     * 
+ * + * optional string php_namespace = 41; + */ + public function getPhpNamespace() + { + return $this->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.
+     * 
+ * + * optional string php_namespace = 41; + */ + public function setPhpNamespace($var) + { + GPBUtil::checkString($var, True); + $this->php_namespace = $var; + $this->has_php_namespace = true; + + return $this; + } + + public function hasPhpNamespace() + { + return $this->has_php_namespace; + } + /** *
      * The parser stores options it doesn't recognize here. See above.
@@ -773,6 +853,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
         $this->uninterpreted_option = $arr;
         $this->has_uninterpreted_option = true;
+
+        return $this;
     }
 
     public function hasUninterpretedOption()
diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
index 450854f1..1e666f31 100644
--- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
+++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
@@ -64,6 +64,8 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class);
         $this->annotation = $arr;
         $this->has_annotation = true;
+
+        return $this;
     }
 
     public function hasAnnotation()
diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
index ed22cc38..8d227e1c 100644
--- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
+++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
@@ -88,6 +88,8 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
         $this->path = $arr;
         $this->has_path = true;
+
+        return $this;
     }
 
     public function hasPath()
@@ -119,6 +121,8 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->source_file = $var;
         $this->has_source_file = true;
+
+        return $this;
     }
 
     public function hasSourceFile()
@@ -152,6 +156,8 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
         GPBUtil::checkInt32($var);
         $this->begin = $var;
         $this->has_begin = true;
+
+        return $this;
     }
 
     public function hasBegin()
@@ -187,6 +193,8 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
         GPBUtil::checkInt32($var);
         $this->end = $var;
         $this->has_end = true;
+
+        return $this;
     }
 
     public function hasEnd()
diff --git a/php/src/Google/Protobuf/Internal/MessageOptions.php b/php/src/Google/Protobuf/Internal/MessageOptions.php
index 747f3294..a5835358 100644
--- a/php/src/Google/Protobuf/Internal/MessageOptions.php
+++ b/php/src/Google/Protobuf/Internal/MessageOptions.php
@@ -155,6 +155,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->message_set_wire_format = $var;
         $this->has_message_set_wire_format = true;
+
+        return $this;
     }
 
     public function hasMessageSetWireFormat()
@@ -190,6 +192,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->no_standard_descriptor_accessor = $var;
         $this->has_no_standard_descriptor_accessor = true;
+
+        return $this;
     }
 
     public function hasNoStandardDescriptorAccessor()
@@ -227,6 +231,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->deprecated = $var;
         $this->has_deprecated = true;
+
+        return $this;
     }
 
     public function hasDeprecated()
@@ -292,6 +298,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->map_entry = $var;
         $this->has_map_entry = true;
+
+        return $this;
     }
 
     public function hasMapEntry()
@@ -323,6 +331,8 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
         $this->uninterpreted_option = $arr;
         $this->has_uninterpreted_option = true;
+
+        return $this;
     }
 
     public function hasUninterpretedOption()
diff --git a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
index 3d8df7af..c3f9f064 100644
--- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
@@ -85,6 +85,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->name = $var;
         $this->has_name = true;
+
+        return $this;
     }
 
     public function hasName()
@@ -118,6 +120,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->input_type = $var;
         $this->has_input_type = true;
+
+        return $this;
     }
 
     public function hasInputType()
@@ -141,6 +145,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->output_type = $var;
         $this->has_output_type = true;
+
+        return $this;
     }
 
     public function hasOutputType()
@@ -164,6 +170,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class);
         $this->options = $var;
         $this->has_options = true;
+
+        return $this;
     }
 
     public function hasOptions()
@@ -195,6 +203,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->client_streaming = $var;
         $this->has_client_streaming = true;
+
+        return $this;
     }
 
     public function hasClientStreaming()
@@ -226,6 +236,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->server_streaming = $var;
         $this->has_server_streaming = true;
+
+        return $this;
     }
 
     public function hasServerStreaming()
diff --git a/php/src/Google/Protobuf/Internal/MethodOptions.php b/php/src/Google/Protobuf/Internal/MethodOptions.php
index 6dca5854..e8d36d3c 100644
--- a/php/src/Google/Protobuf/Internal/MethodOptions.php
+++ b/php/src/Google/Protobuf/Internal/MethodOptions.php
@@ -78,6 +78,8 @@ class MethodOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->deprecated = $var;
         $this->has_deprecated = true;
+
+        return $this;
     }
 
     public function hasDeprecated()
@@ -101,6 +103,8 @@ class MethodOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class);
         $this->idempotency_level = $var;
         $this->has_idempotency_level = true;
+
+        return $this;
     }
 
     public function hasIdempotencyLevel()
@@ -132,6 +136,8 @@ class MethodOptions extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
         $this->uninterpreted_option = $arr;
         $this->has_uninterpreted_option = true;
+
+        return $this;
     }
 
     public function hasUninterpretedOption()
diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
index e5fbe370..744ca638 100644
--- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
@@ -52,6 +52,8 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->name = $var;
         $this->has_name = true;
+
+        return $this;
     }
 
     public function hasName()
@@ -75,6 +77,8 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class);
         $this->options = $var;
         $this->has_options = true;
+
+        return $this;
     }
 
     public function hasOptions()
diff --git a/php/src/Google/Protobuf/Internal/OneofOptions.php b/php/src/Google/Protobuf/Internal/OneofOptions.php
index b61325d2..b3cd51ed 100644
--- a/php/src/Google/Protobuf/Internal/OneofOptions.php
+++ b/php/src/Google/Protobuf/Internal/OneofOptions.php
@@ -55,6 +55,8 @@ class OneofOptions extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
         $this->uninterpreted_option = $arr;
         $this->has_uninterpreted_option = true;
+
+        return $this;
     }
 
     public function hasUninterpretedOption()
diff --git a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
index 47776202..7c85728a 100644
--- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
@@ -57,6 +57,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->name = $var;
         $this->has_name = true;
+
+        return $this;
     }
 
     public function hasName()
@@ -80,6 +82,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class);
         $this->method = $arr;
         $this->has_method = true;
+
+        return $this;
     }
 
     public function hasMethod()
@@ -103,6 +107,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
         GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class);
         $this->options = $var;
         $this->has_options = true;
+
+        return $this;
     }
 
     public function hasOptions()
diff --git a/php/src/Google/Protobuf/Internal/ServiceOptions.php b/php/src/Google/Protobuf/Internal/ServiceOptions.php
index 62323dba..0f3a8d74 100644
--- a/php/src/Google/Protobuf/Internal/ServiceOptions.php
+++ b/php/src/Google/Protobuf/Internal/ServiceOptions.php
@@ -73,6 +73,8 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->deprecated = $var;
         $this->has_deprecated = true;
+
+        return $this;
     }
 
     public function hasDeprecated()
@@ -104,6 +106,8 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
         $this->uninterpreted_option = $arr;
         $this->has_uninterpreted_option = true;
+
+        return $this;
     }
 
     public function hasUninterpretedOption()
diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
index eab60880..7eef3424 100644
--- a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
+++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
@@ -180,6 +180,8 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class);
         $this->location = $arr;
         $this->has_location = true;
+
+        return $this;
     }
 
     public function hasLocation()
diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
index 5a02b26c..cf23e38b 100644
--- a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
+++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
@@ -182,6 +182,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
         $this->path = $arr;
         $this->has_path = true;
+
+        return $this;
     }
 
     public function hasPath()
@@ -221,6 +223,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
         $this->span = $arr;
         $this->has_span = true;
+
+        return $this;
     }
 
     public function hasSpan()
@@ -322,6 +326,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->leading_comments = $var;
         $this->has_leading_comments = true;
+
+        return $this;
     }
 
     public function hasLeadingComments()
@@ -345,6 +351,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->trailing_comments = $var;
         $this->has_trailing_comments = true;
+
+        return $this;
     }
 
     public function hasTrailingComments()
@@ -368,6 +376,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
         $this->leading_detached_comments = $arr;
         $this->has_leading_detached_comments = true;
+
+        return $this;
     }
 
     public function hasLeadingDetachedComments()
diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption.php b/php/src/Google/Protobuf/Internal/UninterpretedOption.php
index 28655019..08e071d4 100644
--- a/php/src/Google/Protobuf/Internal/UninterpretedOption.php
+++ b/php/src/Google/Protobuf/Internal/UninterpretedOption.php
@@ -87,6 +87,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class);
         $this->name = $arr;
         $this->has_name = true;
+
+        return $this;
     }
 
     public function hasName()
@@ -120,6 +122,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->identifier_value = $var;
         $this->has_identifier_value = true;
+
+        return $this;
     }
 
     public function hasIdentifierValue()
@@ -143,6 +147,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         GPBUtil::checkUint64($var);
         $this->positive_int_value = $var;
         $this->has_positive_int_value = true;
+
+        return $this;
     }
 
     public function hasPositiveIntValue()
@@ -166,6 +172,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         GPBUtil::checkInt64($var);
         $this->negative_int_value = $var;
         $this->has_negative_int_value = true;
+
+        return $this;
     }
 
     public function hasNegativeIntValue()
@@ -189,6 +197,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         GPBUtil::checkDouble($var);
         $this->double_value = $var;
         $this->has_double_value = true;
+
+        return $this;
     }
 
     public function hasDoubleValue()
@@ -212,6 +222,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, False);
         $this->string_value = $var;
         $this->has_string_value = true;
+
+        return $this;
     }
 
     public function hasStringValue()
@@ -235,6 +247,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->aggregate_value = $var;
         $this->has_aggregate_value = true;
+
+        return $this;
     }
 
     public function hasAggregateValue()
diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
index 86484d23..eb27754c 100644
--- a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
+++ b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
@@ -56,6 +56,8 @@ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message
         GPBUtil::checkString($var, True);
         $this->name_part = $var;
         $this->has_name_part = true;
+
+        return $this;
     }
 
     public function hasNamePart()
@@ -79,6 +81,8 @@ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message
         GPBUtil::checkBool($var);
         $this->is_extension = $var;
         $this->has_is_extension = true;
+
+        return $this;
     }
 
     public function hasIsExtension()
diff --git a/php/src/Google/Protobuf/descriptor.php b/php/src/Google/Protobuf/descriptor.php
index 35e4929b..b7a3a550 100644
--- a/php/src/Google/Protobuf/descriptor.php
+++ b/php/src/Google/Protobuf/descriptor.php
@@ -282,6 +282,19 @@ function getFullClassName(
 
     $class_name_without_package =
         getClassNameWithoutPackage($message_name_without_package, $file_proto);
+
+    $option = $file_proto->getOptions();
+    if (!is_null($option) && $option->hasPhpNamespace()) {
+        $namespace = $option->getPhpNamespace();
+        if ($namespace !== "") {
+            $classname = $namespace . "\\" . $class_name_without_package;
+            return;
+        } else {
+            $classname = $class_name_without_package;
+            return;
+        }
+    }
+
     if ($package === "") {
         $classname = $class_name_without_package;
     } else {
-- 
cgit v1.2.3