1ffe3c632Sopenharmony_ci<?php 2ffe3c632Sopenharmony_ci 3ffe3c632Sopenharmony_ci// Protocol Buffers - Google's data interchange format 4ffe3c632Sopenharmony_ci// Copyright 2008 Google Inc. All rights reserved. 5ffe3c632Sopenharmony_ci// https://developers.google.com/protocol-buffers/ 6ffe3c632Sopenharmony_ci// 7ffe3c632Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 8ffe3c632Sopenharmony_ci// modification, are permitted provided that the following conditions are 9ffe3c632Sopenharmony_ci// met: 10ffe3c632Sopenharmony_ci// 11ffe3c632Sopenharmony_ci// * Redistributions of source code must retain the above copyright 12ffe3c632Sopenharmony_ci// notice, this list of conditions and the following disclaimer. 13ffe3c632Sopenharmony_ci// * Redistributions in binary form must reproduce the above 14ffe3c632Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 15ffe3c632Sopenharmony_ci// in the documentation and/or other materials provided with the 16ffe3c632Sopenharmony_ci// distribution. 17ffe3c632Sopenharmony_ci// * Neither the name of Google Inc. nor the names of its 18ffe3c632Sopenharmony_ci// contributors may be used to endorse or promote products derived from 19ffe3c632Sopenharmony_ci// this software without specific prior written permission. 20ffe3c632Sopenharmony_ci// 21ffe3c632Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22ffe3c632Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23ffe3c632Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24ffe3c632Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25ffe3c632Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26ffe3c632Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27ffe3c632Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28ffe3c632Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29ffe3c632Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30ffe3c632Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31ffe3c632Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32ffe3c632Sopenharmony_ci 33ffe3c632Sopenharmony_cinamespace Google\Protobuf\Internal; 34ffe3c632Sopenharmony_ci 35ffe3c632Sopenharmony_ciclass Descriptor 36ffe3c632Sopenharmony_ci{ 37ffe3c632Sopenharmony_ci use HasPublicDescriptorTrait; 38ffe3c632Sopenharmony_ci 39ffe3c632Sopenharmony_ci private $full_name; 40ffe3c632Sopenharmony_ci private $field = []; 41ffe3c632Sopenharmony_ci private $json_to_field = []; 42ffe3c632Sopenharmony_ci private $name_to_field = []; 43ffe3c632Sopenharmony_ci private $index_to_field = []; 44ffe3c632Sopenharmony_ci private $nested_type = []; 45ffe3c632Sopenharmony_ci private $enum_type = []; 46ffe3c632Sopenharmony_ci private $klass; 47ffe3c632Sopenharmony_ci private $legacy_klass; 48ffe3c632Sopenharmony_ci private $options; 49ffe3c632Sopenharmony_ci private $oneof_decl = []; 50ffe3c632Sopenharmony_ci 51ffe3c632Sopenharmony_ci public function __construct() 52ffe3c632Sopenharmony_ci { 53ffe3c632Sopenharmony_ci $this->public_desc = new \Google\Protobuf\Descriptor($this); 54ffe3c632Sopenharmony_ci } 55ffe3c632Sopenharmony_ci 56ffe3c632Sopenharmony_ci public function addOneofDecl($oneof) 57ffe3c632Sopenharmony_ci { 58ffe3c632Sopenharmony_ci $this->oneof_decl[] = $oneof; 59ffe3c632Sopenharmony_ci } 60ffe3c632Sopenharmony_ci 61ffe3c632Sopenharmony_ci public function getOneofDecl() 62ffe3c632Sopenharmony_ci { 63ffe3c632Sopenharmony_ci return $this->oneof_decl; 64ffe3c632Sopenharmony_ci } 65ffe3c632Sopenharmony_ci 66ffe3c632Sopenharmony_ci public function setFullName($full_name) 67ffe3c632Sopenharmony_ci { 68ffe3c632Sopenharmony_ci $this->full_name = $full_name; 69ffe3c632Sopenharmony_ci } 70ffe3c632Sopenharmony_ci 71ffe3c632Sopenharmony_ci public function getFullName() 72ffe3c632Sopenharmony_ci { 73ffe3c632Sopenharmony_ci return $this->full_name; 74ffe3c632Sopenharmony_ci } 75ffe3c632Sopenharmony_ci 76ffe3c632Sopenharmony_ci public function addField($field) 77ffe3c632Sopenharmony_ci { 78ffe3c632Sopenharmony_ci $this->field[$field->getNumber()] = $field; 79ffe3c632Sopenharmony_ci $this->json_to_field[$field->getJsonName()] = $field; 80ffe3c632Sopenharmony_ci $this->name_to_field[$field->getName()] = $field; 81ffe3c632Sopenharmony_ci $this->index_to_field[] = $field; 82ffe3c632Sopenharmony_ci } 83ffe3c632Sopenharmony_ci 84ffe3c632Sopenharmony_ci public function getField() 85ffe3c632Sopenharmony_ci { 86ffe3c632Sopenharmony_ci return $this->field; 87ffe3c632Sopenharmony_ci } 88ffe3c632Sopenharmony_ci 89ffe3c632Sopenharmony_ci public function addNestedType($desc) 90ffe3c632Sopenharmony_ci { 91ffe3c632Sopenharmony_ci $this->nested_type[] = $desc; 92ffe3c632Sopenharmony_ci } 93ffe3c632Sopenharmony_ci 94ffe3c632Sopenharmony_ci public function getNestedType() 95ffe3c632Sopenharmony_ci { 96ffe3c632Sopenharmony_ci return $this->nested_type; 97ffe3c632Sopenharmony_ci } 98ffe3c632Sopenharmony_ci 99ffe3c632Sopenharmony_ci public function addEnumType($desc) 100ffe3c632Sopenharmony_ci { 101ffe3c632Sopenharmony_ci $this->enum_type[] = $desc; 102ffe3c632Sopenharmony_ci } 103ffe3c632Sopenharmony_ci 104ffe3c632Sopenharmony_ci public function getEnumType() 105ffe3c632Sopenharmony_ci { 106ffe3c632Sopenharmony_ci return $this->enum_type; 107ffe3c632Sopenharmony_ci } 108ffe3c632Sopenharmony_ci 109ffe3c632Sopenharmony_ci public function getFieldByNumber($number) 110ffe3c632Sopenharmony_ci { 111ffe3c632Sopenharmony_ci if (!isset($this->field[$number])) { 112ffe3c632Sopenharmony_ci return NULL; 113ffe3c632Sopenharmony_ci } else { 114ffe3c632Sopenharmony_ci return $this->field[$number]; 115ffe3c632Sopenharmony_ci } 116ffe3c632Sopenharmony_ci } 117ffe3c632Sopenharmony_ci 118ffe3c632Sopenharmony_ci public function getFieldByJsonName($json_name) 119ffe3c632Sopenharmony_ci { 120ffe3c632Sopenharmony_ci if (!isset($this->json_to_field[$json_name])) { 121ffe3c632Sopenharmony_ci return NULL; 122ffe3c632Sopenharmony_ci } else { 123ffe3c632Sopenharmony_ci return $this->json_to_field[$json_name]; 124ffe3c632Sopenharmony_ci } 125ffe3c632Sopenharmony_ci } 126ffe3c632Sopenharmony_ci 127ffe3c632Sopenharmony_ci public function getFieldByName($name) 128ffe3c632Sopenharmony_ci { 129ffe3c632Sopenharmony_ci if (!isset($this->name_to_field[$name])) { 130ffe3c632Sopenharmony_ci return NULL; 131ffe3c632Sopenharmony_ci } else { 132ffe3c632Sopenharmony_ci return $this->name_to_field[$name]; 133ffe3c632Sopenharmony_ci } 134ffe3c632Sopenharmony_ci } 135ffe3c632Sopenharmony_ci 136ffe3c632Sopenharmony_ci public function getFieldByIndex($index) 137ffe3c632Sopenharmony_ci { 138ffe3c632Sopenharmony_ci if (count($this->index_to_field) <= $index) { 139ffe3c632Sopenharmony_ci return NULL; 140ffe3c632Sopenharmony_ci } else { 141ffe3c632Sopenharmony_ci return $this->index_to_field[$index]; 142ffe3c632Sopenharmony_ci } 143ffe3c632Sopenharmony_ci } 144ffe3c632Sopenharmony_ci 145ffe3c632Sopenharmony_ci public function setClass($klass) 146ffe3c632Sopenharmony_ci { 147ffe3c632Sopenharmony_ci $this->klass = $klass; 148ffe3c632Sopenharmony_ci } 149ffe3c632Sopenharmony_ci 150ffe3c632Sopenharmony_ci public function getClass() 151ffe3c632Sopenharmony_ci { 152ffe3c632Sopenharmony_ci return $this->klass; 153ffe3c632Sopenharmony_ci } 154ffe3c632Sopenharmony_ci 155ffe3c632Sopenharmony_ci public function setLegacyClass($klass) 156ffe3c632Sopenharmony_ci { 157ffe3c632Sopenharmony_ci $this->legacy_klass = $klass; 158ffe3c632Sopenharmony_ci } 159ffe3c632Sopenharmony_ci 160ffe3c632Sopenharmony_ci public function getLegacyClass() 161ffe3c632Sopenharmony_ci { 162ffe3c632Sopenharmony_ci return $this->legacy_klass; 163ffe3c632Sopenharmony_ci } 164ffe3c632Sopenharmony_ci 165ffe3c632Sopenharmony_ci public function setOptions($options) 166ffe3c632Sopenharmony_ci { 167ffe3c632Sopenharmony_ci $this->options = $options; 168ffe3c632Sopenharmony_ci } 169ffe3c632Sopenharmony_ci 170ffe3c632Sopenharmony_ci public function getOptions() 171ffe3c632Sopenharmony_ci { 172ffe3c632Sopenharmony_ci return $this->options; 173ffe3c632Sopenharmony_ci } 174ffe3c632Sopenharmony_ci 175ffe3c632Sopenharmony_ci public static function buildFromProto($proto, $file_proto, $containing) 176ffe3c632Sopenharmony_ci { 177ffe3c632Sopenharmony_ci $desc = new Descriptor(); 178ffe3c632Sopenharmony_ci 179ffe3c632Sopenharmony_ci $message_name_without_package = ""; 180ffe3c632Sopenharmony_ci $classname = ""; 181ffe3c632Sopenharmony_ci $legacy_classname = ""; 182ffe3c632Sopenharmony_ci $fullname = ""; 183ffe3c632Sopenharmony_ci GPBUtil::getFullClassName( 184ffe3c632Sopenharmony_ci $proto, 185ffe3c632Sopenharmony_ci $containing, 186ffe3c632Sopenharmony_ci $file_proto, 187ffe3c632Sopenharmony_ci $message_name_without_package, 188ffe3c632Sopenharmony_ci $classname, 189ffe3c632Sopenharmony_ci $legacy_classname, 190ffe3c632Sopenharmony_ci $fullname); 191ffe3c632Sopenharmony_ci $desc->setFullName($fullname); 192ffe3c632Sopenharmony_ci $desc->setClass($classname); 193ffe3c632Sopenharmony_ci $desc->setLegacyClass($legacy_classname); 194ffe3c632Sopenharmony_ci $desc->setOptions($proto->getOptions()); 195ffe3c632Sopenharmony_ci 196ffe3c632Sopenharmony_ci foreach ($proto->getField() as $field_proto) { 197ffe3c632Sopenharmony_ci $desc->addField(FieldDescriptor::buildFromProto($field_proto)); 198ffe3c632Sopenharmony_ci } 199ffe3c632Sopenharmony_ci 200ffe3c632Sopenharmony_ci // Handle nested types. 201ffe3c632Sopenharmony_ci foreach ($proto->getNestedType() as $nested_proto) { 202ffe3c632Sopenharmony_ci $desc->addNestedType(Descriptor::buildFromProto( 203ffe3c632Sopenharmony_ci $nested_proto, $file_proto, $message_name_without_package)); 204ffe3c632Sopenharmony_ci } 205ffe3c632Sopenharmony_ci 206ffe3c632Sopenharmony_ci // Handle nested enum. 207ffe3c632Sopenharmony_ci foreach ($proto->getEnumType() as $enum_proto) { 208ffe3c632Sopenharmony_ci $desc->addEnumType(EnumDescriptor::buildFromProto( 209ffe3c632Sopenharmony_ci $enum_proto, $file_proto, $message_name_without_package)); 210ffe3c632Sopenharmony_ci } 211ffe3c632Sopenharmony_ci 212ffe3c632Sopenharmony_ci // Handle oneof fields. 213ffe3c632Sopenharmony_ci $index = 0; 214ffe3c632Sopenharmony_ci foreach ($proto->getOneofDecl() as $oneof_proto) { 215ffe3c632Sopenharmony_ci $desc->addOneofDecl( 216ffe3c632Sopenharmony_ci OneofDescriptor::buildFromProto($oneof_proto, $desc, $index)); 217ffe3c632Sopenharmony_ci $index++; 218ffe3c632Sopenharmony_ci } 219ffe3c632Sopenharmony_ci 220ffe3c632Sopenharmony_ci return $desc; 221ffe3c632Sopenharmony_ci } 222ffe3c632Sopenharmony_ci} 223