diff options
author | Jisi Liu <liujisi@google.com> | 2018-01-04 14:26:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-04 14:26:24 -0800 |
commit | a3868af12be724f808faa21a29e7b4931e30bed1 (patch) | |
tree | 3df23c4174287023b569108eb133db0f9c310646 /php/src/Google/Protobuf/Internal/Message.php | |
parent | eca1d2a7113b3d57f900f69661342c0078c956c4 (diff) | |
parent | ec826c5a592126ddb6b12b47e6e1fb6232ce340d (diff) | |
download | protobuf-a3868af12be724f808faa21a29e7b4931e30bed1.tar.gz protobuf-a3868af12be724f808faa21a29e7b4931e30bed1.tar.bz2 protobuf-a3868af12be724f808faa21a29e7b4931e30bed1.zip |
Merge pull request #4131 from pherl/merge
Merge 3.5.x branch into master
Diffstat (limited to 'php/src/Google/Protobuf/Internal/Message.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/Message.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 26d20575..b7f83c57 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -583,6 +583,34 @@ class Message public function discardUnknownFields() { $this->unknown = ""; + foreach ($this->desc->getField() as $field) { + if ($field->getType() != GPBType::MESSAGE) { + continue; + } + if ($field->isMap()) { + $value_field = $field->getMessageType()->getFieldByNumber(2); + if ($value_field->getType() != GPBType::MESSAGE) { + continue; + } + $getter = $field->getGetter(); + $map = $this->$getter(); + foreach ($map as $key => $value) { + $value->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + $getter = $field->getGetter(); + $arr = $this->$getter(); + foreach ($arr as $sub) { + $sub->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + $getter = $field->getGetter(); + $sub = $this->$getter(); + if (!is_null($sub)) { + $sub->discardUnknownFields(); + } + } + } } /** @@ -1083,7 +1111,7 @@ class Message } try { $this->mergeFromJsonArray($array); - } catch (Exception $e) { + } catch (\Exception $e) { throw new GPBDecodeException($e->getMessage()); } } |