Fixes bugs of isSynthetic and makes containing_oneof work
This commit is contained in:
parent
238331b359
commit
594f2a9b0d
@ -82,14 +82,6 @@ class FieldDescriptor
|
||||
return $this->internal_desc->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOneofIndex()
|
||||
{
|
||||
return $this->internal_desc->getOneofIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OneofDescriptor
|
||||
*/
|
||||
|
@ -193,10 +193,6 @@ class Descriptor
|
||||
$desc->setLegacyClass($legacy_classname);
|
||||
$desc->setOptions($proto->getOptions());
|
||||
|
||||
foreach ($proto->getField() as $field_proto) {
|
||||
$desc->addField(FieldDescriptor::buildFromProto($field_proto, $desc));
|
||||
}
|
||||
|
||||
// Handle nested types.
|
||||
foreach ($proto->getNestedType() as $nested_proto) {
|
||||
$desc->addNestedType(Descriptor::buildFromProto(
|
||||
@ -217,6 +213,11 @@ class Descriptor
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,6 @@ class FieldDescriptor
|
||||
private $oneof_index = -1;
|
||||
private $proto3_optional;
|
||||
|
||||
/** @var Descriptor $containing_type */
|
||||
private $containing_type;
|
||||
/** @var OneofDescriptor $containing_oneof */
|
||||
private $containing_oneof;
|
||||
|
||||
@ -242,10 +240,10 @@ class FieldDescriptor
|
||||
|
||||
/**
|
||||
* @param FieldDescriptorProto $proto
|
||||
* @param Descriptor $parent_desc
|
||||
* @param Descriptor $desc
|
||||
* @return FieldDescriptor
|
||||
*/
|
||||
public static function getFieldDescriptor($proto, $parent_desc)
|
||||
public static function getFieldDescriptor($proto, $desc)
|
||||
{
|
||||
$type_name = null;
|
||||
$type = $proto->getType();
|
||||
@ -261,10 +259,10 @@ class FieldDescriptor
|
||||
|
||||
if ($proto->hasOneofIndex()) {
|
||||
$oneof_index = $proto->getOneofIndex();
|
||||
$containing_oneof = $parent_desc->getOneofDecl()[$oneof_index];
|
||||
$containing_oneof = $desc->getOneofDecl()[$oneof_index];
|
||||
} else {
|
||||
$containing_oneof = null;
|
||||
$oneof_index = -1;
|
||||
$containing_oneof = null;
|
||||
}
|
||||
// TODO: once proto2 is supported, this default should be false
|
||||
// for proto2.
|
||||
@ -284,7 +282,6 @@ class FieldDescriptor
|
||||
|
||||
$field = new FieldDescriptor();
|
||||
$field->setName($proto->getName());
|
||||
$field->containing_type = $parent_desc;
|
||||
$field->containing_oneof = $containing_oneof;
|
||||
|
||||
$json_name = $proto->hasJsonName() ? $proto->getJsonName() :
|
||||
|
@ -67,7 +67,8 @@ class OneofDescriptor
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user