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