diff options
Diffstat (limited to 'php/src/Google/Protobuf/Internal/Message.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/Message.php | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 10c639ac..9ba249a0 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -373,7 +373,7 @@ class Message $getter = $field->getGetter(); while ($input->bytesUntilLimit() > 0) { self::parseFieldFromStreamNoTag($input, $field, $value); - $this->$getter()[] = $value; + $this->appendHelper($field, $value); } $input->popLimit($limit); return; @@ -382,11 +382,9 @@ class Message } if ($field->isMap()) { - $getter = $field->getGetter(); - $this->$getter()[$value->getKey()] = $value->getValue(); + $this->kvUpdateHelper($field, $value->getKey(), $value->getValue()); } else if ($field->isRepeated()) { - $getter = $field->getGetter(); - $this->$getter()[] = $value; + $this->appendHelper($field, $value); } else { $setter = $field->getSetter(); $this->$setter($value); @@ -533,9 +531,10 @@ class Message $klass = $value_field->getMessageType()->getClass(); $copy = new $klass; $copy->mergeFrom($value); - $this->$getter()[$key] = $copy; + + $this->kvUpdateHelper($field, $key, $copy); } else { - $this->$getter()[$key] = $value; + $this->kvUpdateHelper($field, $key, $value); } } } @@ -546,9 +545,9 @@ class Message $klass = $field->getMessageType()->getClass(); $copy = new $klass; $copy->mergeFrom($tmp); - $this->$getter()[] = $copy; + $this->appendHelper($field, $copy); } else { - $this->$getter()[] = $tmp; + $this->appendHelper($field, $tmp); } } } @@ -896,4 +895,30 @@ class Message } return $size; } + + private function appendHelper($field, $append_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[] = $append_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + private function kvUpdateHelper($field, $update_key, $update_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[$update_key] = $update_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } } |