diff options
author | Brent Shaffer <betterbrent@google.com> | 2017-05-29 10:39:14 -0700 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2017-05-29 10:39:14 -0700 |
commit | 4d5daf4ef97918176b892dbedce17b1d854ffe8e (patch) | |
tree | 878663f363714f9f7b1e7ab3f2ea74d1d0a1321c | |
parent | 4674cc7c073f1b8d5efd2a42ffcf3ca30a907bfe (diff) | |
download | protobuf-4d5daf4ef97918176b892dbedce17b1d854ffe8e.tar.gz protobuf-4d5daf4ef97918176b892dbedce17b1d854ffe8e.tar.bz2 protobuf-4d5daf4ef97918176b892dbedce17b1d854ffe8e.zip |
Adds fluent setters for PHP (#3130)
-rw-r--r-- | php/tests/generated_class_test.php | 13 | ||||
-rw-r--r-- | src/google/protobuf/compiler/php/php_generator.cc | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 21ee8490..b42397bb 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -877,4 +877,17 @@ class GeneratedClassTest extends TestBase $m = new \Foo\PBEmpty(); $m = new \PrefixEmpty(); } + + ######################################################### + # Test fluent setters. + ######################################################### + + public function testFluentSetters() + { + $m = (new TestMessage()) + ->setOptionalInt32(1) + ->setOptionalInt64(2); + $this->assertSame(1, $m->getOptionalInt32()); + $this->assertSame(2, $m->getOptionalInt64()); + } } diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index ea850c0f..54fafc40 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -530,6 +530,8 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, "field_name", field->name()); } + printer->Print("\nreturn $this;\n"); + Outdent(printer); printer->Print( |