MapEntry.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // Protocol Buffers - Google's data interchange format
  3. // Copyright 2008 Google Inc. All rights reserved.
  4. //
  5. // Use of this source code is governed by a BSD-style
  6. // license that can be found in the LICENSE file or at
  7. // https://developers.google.com/open-source/licenses/bsd
  8. namespace Google\Protobuf\Internal;
  9. use Google\Protobuf\Internal\GPBType;
  10. use Google\Protobuf\Internal\Message;
  11. class MapEntry extends Message
  12. {
  13. public $key;
  14. public $value;
  15. public function __construct($desc) {
  16. parent::__construct($desc);
  17. // For MapEntry, getValue should always return a valid value. Thus, we
  18. // need to create a default instance value if the value type is
  19. // message, in case no value is provided in data.
  20. $value_field = $desc->getFieldByNumber(2);
  21. if ($value_field->getType() == GPBType::MESSAGE) {
  22. $klass = $value_field->getMessageType()->getClass();
  23. $value = new $klass;
  24. $this->setValue($value);
  25. }
  26. }
  27. public function setKey($key) {
  28. $this->key = $key;
  29. }
  30. public function getKey() {
  31. return $this->key;
  32. }
  33. public function setValue($value) {
  34. $this->value = $value;
  35. }
  36. public function getValue() {
  37. return $this->value;
  38. }
  39. }