aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Shaffer <betterbrent@google.com>2018-06-19 22:20:56 +0200
committerPaul Yang <TeBoring@users.noreply.github.com>2018-06-19 13:20:56 -0700
commitabac8080004ce018287275e41de40f57800f97aa (patch)
tree783d78357b35f4f68df7980adf5452850bd3c656
parent7a23a2ea5e058d5b814a872c5797d45f0f55a2a6 (diff)
downloadprotobuf-php-generated-dev.tar.gz
protobuf-php-generated-dev.tar.bz2
protobuf-php-generated-dev.zip
adds PHP typehints for message setters (#4533)php-generated-dev
-rw-r--r--php/src/Google/Protobuf/Internal/DescriptorProto.php2
-rw-r--r--php/src/Google/Protobuf/Internal/EnumDescriptorProto.php2
-rw-r--r--php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php2
-rw-r--r--php/src/Google/Protobuf/Internal/FieldDescriptorProto.php2
-rw-r--r--php/src/Google/Protobuf/Internal/FileDescriptorProto.php4
-rw-r--r--php/src/Google/Protobuf/Internal/MethodDescriptorProto.php2
-rw-r--r--php/src/Google/Protobuf/Internal/OneofDescriptorProto.php2
-rw-r--r--php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php2
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc16
9 files changed, 21 insertions, 13 deletions
diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php
index 3b215d52..707e39d0 100644
--- a/php/src/Google/Protobuf/Internal/DescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php
@@ -306,7 +306,7 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\MessageOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\MessageOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
index da30fa99..df912e55 100644
--- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
@@ -143,7 +143,7 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\EnumOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
index 50bda008..6f4a6dd7 100644
--- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
@@ -119,7 +119,7 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\EnumValueOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\EnumValueOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
index e5781975..77b99887 100644
--- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
@@ -455,7 +455,7 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FieldOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\FieldOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
index cb10aa79..4b6e3a34 100644
--- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
@@ -429,7 +429,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\FileOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\FileOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class);
$this->options = $var;
@@ -467,7 +467,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\SourceCodeInfo $var
* @return $this
*/
- public function setSourceCodeInfo($var)
+ public function setSourceCodeInfo(\Google\Protobuf\Internal\SourceCodeInfo $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class);
$this->source_code_info = $var;
diff --git a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
index 1bd5dd3e..6186cd1c 100644
--- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
@@ -182,7 +182,7 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\MethodOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\MethodOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
index 9ecfe5cb..d4105e46 100644
--- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
@@ -85,7 +85,7 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\OneofOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\OneofOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class);
$this->options = $var;
diff --git a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
index 8de7afd0..f5b4cee5 100644
--- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
@@ -119,7 +119,7 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
* @param \Google\Protobuf\Internal\ServiceOptions $var
* @return $this
*/
- public function setOptions($var)
+ public function setOptions(\Google\Protobuf\Internal\ServiceOptions $var = null)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class);
$this->options = $var;
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index cdb2f509..0bfe10c9 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -664,10 +664,18 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
// Generate setter.
GenerateFieldDocComment(printer, field, is_descriptor, kFieldSetter);
- printer->Print(
- "public function set^camel_name^($var)\n"
- "{\n",
- "camel_name", UnderscoresToCamelCase(field->name(), true));
+ if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_repeated()) {
+ printer->Print(
+ "public function set^camel_name^(^typehint^ $var = null)\n"
+ "{\n",
+ "camel_name", UnderscoresToCamelCase(field->name(), true),
+ "typehint", "\\" + FullClassName(field->message_type(), is_descriptor));
+ } else {
+ printer->Print(
+ "public function set^camel_name^($var)\n"
+ "{\n",
+ "camel_name", UnderscoresToCamelCase(field->name(), true));
+ }
Indent(printer);