Fixes bugs of isSynthetic and makes containing_oneof work

pull/10102/head
Thanet (Knack) Praneenararat 3 years ago
parent 238331b359
commit 594f2a9b0d
  1. 8
      php/src/Google/Protobuf/FieldDescriptor.php
  2. 9
      php/src/Google/Protobuf/Internal/Descriptor.php
  3. 11
      php/src/Google/Protobuf/Internal/FieldDescriptor.php
  4. 3
      php/src/Google/Protobuf/Internal/OneofDescriptor.php

@ -82,14 +82,6 @@ class FieldDescriptor
return $this->internal_desc->getType(); return $this->internal_desc->getType();
} }
/**
* @return int
*/
public function getOneofIndex()
{
return $this->internal_desc->getOneofIndex();
}
/** /**
* @return OneofDescriptor * @return OneofDescriptor
*/ */

@ -193,10 +193,6 @@ class Descriptor
$desc->setLegacyClass($legacy_classname); $desc->setLegacyClass($legacy_classname);
$desc->setOptions($proto->getOptions()); $desc->setOptions($proto->getOptions());
foreach ($proto->getField() as $field_proto) {
$desc->addField(FieldDescriptor::buildFromProto($field_proto, $desc));
}
// Handle nested types. // Handle nested types.
foreach ($proto->getNestedType() as $nested_proto) { foreach ($proto->getNestedType() as $nested_proto) {
$desc->addNestedType(Descriptor::buildFromProto( $desc->addNestedType(Descriptor::buildFromProto(
@ -217,6 +213,11 @@ class Descriptor
$index++; $index++;
} }
// Pass the descriptor to build FieldDescriptor after the OneofDescriptors are populated.
foreach ($proto->getField() as $field_proto) {
$desc->addField(FieldDescriptor::buildFromProto($field_proto, $desc));
}
return $desc; return $desc;
} }
} }

@ -49,8 +49,6 @@ class FieldDescriptor
private $oneof_index = -1; private $oneof_index = -1;
private $proto3_optional; private $proto3_optional;
/** @var Descriptor $containing_type */
private $containing_type;
/** @var OneofDescriptor $containing_oneof */ /** @var OneofDescriptor $containing_oneof */
private $containing_oneof; private $containing_oneof;
@ -242,10 +240,10 @@ class FieldDescriptor
/** /**
* @param FieldDescriptorProto $proto * @param FieldDescriptorProto $proto
* @param Descriptor $parent_desc * @param Descriptor $desc
* @return FieldDescriptor * @return FieldDescriptor
*/ */
public static function getFieldDescriptor($proto, $parent_desc) public static function getFieldDescriptor($proto, $desc)
{ {
$type_name = null; $type_name = null;
$type = $proto->getType(); $type = $proto->getType();
@ -261,10 +259,10 @@ class FieldDescriptor
if ($proto->hasOneofIndex()) { if ($proto->hasOneofIndex()) {
$oneof_index = $proto->getOneofIndex(); $oneof_index = $proto->getOneofIndex();
$containing_oneof = $parent_desc->getOneofDecl()[$oneof_index]; $containing_oneof = $desc->getOneofDecl()[$oneof_index];
} else { } else {
$containing_oneof = null;
$oneof_index = -1; $oneof_index = -1;
$containing_oneof = null;
} }
// TODO: once proto2 is supported, this default should be false // TODO: once proto2 is supported, this default should be false
// for proto2. // for proto2.
@ -284,7 +282,6 @@ class FieldDescriptor
$field = new FieldDescriptor(); $field = new FieldDescriptor();
$field->setName($proto->getName()); $field->setName($proto->getName());
$field->containing_type = $parent_desc;
$field->containing_oneof = $containing_oneof; $field->containing_oneof = $containing_oneof;
$json_name = $proto->hasJsonName() ? $proto->getJsonName() : $json_name = $proto->hasJsonName() ? $proto->getJsonName() :

@ -67,7 +67,8 @@ class OneofDescriptor
public function isSynthetic() public function isSynthetic()
{ {
return count($this->fields) === 1 && $this->fields[0]->getProto3Optional(); return !is_null($this->fields) && count($this->fields) === 1
&& $this->fields[0]->getProto3Optional();
} }
public static function buildFromProto($oneof_proto, $desc, $index) public static function buildFromProto($oneof_proto, $desc, $index)

Loading…
Cancel
Save