diff options
author | Ryan Gordon <ryan@quizlet.com> | 2017-06-19 18:15:49 -0700 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2017-06-19 18:15:49 -0700 |
commit | 703cd8e11c8d34283d4c8bf869c61866e8211c9d (patch) | |
tree | c0b767f176d16e6ccfea69ad6f53d6d375f48933 /php/src/Google/Protobuf/Internal | |
parent | 13255889820dbd56f1574d9730465ca834c22bd2 (diff) |
Switch to addEnumType to fix fatal error (#3225)
* Switch to addEnumType to fix fatal error
* Fixing more cases of HHVM incompatibility
* Updating tests to be hhvm compatible
* Fixing tests
* Fixing merge
* Don't use call_user_func, should hopefully fix tests
* Fixing spelling
* Fixing another misspelling in a test
* Fixing placement of append and kvUpdate functions
* Actually fix function helpers
* Remove double addEnumType. How did this ever work?
* Fixing a couple more tests
* Only use the setter if the return value isn't an object
Diffstat (limited to 'php/src/Google/Protobuf/Internal')
-rw-r--r-- | php/src/Google/Protobuf/Internal/FileDescriptor.php | 11 | ||||
-rw-r--r-- | php/src/Google/Protobuf/Internal/Message.php | 43 |
2 files changed, 39 insertions, 15 deletions
diff --git a/php/src/Google/Protobuf/Internal/FileDescriptor.php b/php/src/Google/Protobuf/Internal/FileDescriptor.php index 14716390..038da38c 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptor.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptor.php @@ -78,12 +78,11 @@ class FileDescriptor $message_proto, $proto, "")); } foreach ($proto->getEnumType() as $enum_proto) { - $file->getEnumType()[] = - $file->addEnumType( - EnumDescriptor::buildFromProto( - $enum_proto, - $proto, - "")); + $file->addEnumType( + EnumDescriptor::buildFromProto( + $enum_proto, + $proto, + "")); } return $file; } 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); + } + } } |