aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/src/Google/Protobuf/Internal/OneofDescriptor.php
diff options
context:
space:
mode:
authorGravatar michaelbausor <michaelbausor@google.com>2017-08-04 16:35:22 -0700
committerGravatar Paul Yang <TeBoring@users.noreply.github.com>2017-08-04 16:35:22 -0700
commit21b0e5587c01948927ede9be789671ff116b7ad4 (patch)
tree8bb156c68677804739e65c3b4ee6cd9f891797f2 /php/src/Google/Protobuf/Internal/OneofDescriptor.php
parent1ab5adbdec4d6487c8e6f230138092d27d6a0818 (diff)
Update PHP descriptors (#3391)
* Add descriptors test * Update descriptors tests * Add public descriptors * Add test_desriptors.proto to test script * Update composer files * Remove references to GPBType, update tests to be compatible with c * Update for c extension compatibility * Remove nested enums for descriptor, update tests * Strip leading '.' from descriptor name * Update tests with test for getClass, fix OneofDescriptor * Add new files to Makefile.am
Diffstat (limited to 'php/src/Google/Protobuf/Internal/OneofDescriptor.php')
-rw-r--r--php/src/Google/Protobuf/Internal/OneofDescriptor.php15
1 files changed, 13 insertions, 2 deletions
diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptor.php b/php/src/Google/Protobuf/Internal/OneofDescriptor.php
index 57961f39..67b107f6 100644
--- a/php/src/Google/Protobuf/Internal/OneofDescriptor.php
+++ b/php/src/Google/Protobuf/Internal/OneofDescriptor.php
@@ -34,10 +34,16 @@ namespace Google\Protobuf\Internal;
class OneofDescriptor
{
+ use HasPublicDescriptorTrait;
private $name;
private $fields;
+ public function __construct()
+ {
+ $this->public_desc = new \Google\Protobuf\OneofDescriptor($this);
+ }
+
public function setName($name)
{
$this->name = $name;
@@ -48,7 +54,7 @@ class OneofDescriptor
return $this->name;
}
- public function addField(Descriptor $field)
+ public function addField(FieldDescriptor $field)
{
$this->fields[] = $field;
}
@@ -58,10 +64,15 @@ class OneofDescriptor
return $this->fields;
}
- public static function buildFromProto($oneof_proto)
+ public static function buildFromProto($oneof_proto, $desc, $index)
{
$oneof = new OneofDescriptor();
$oneof->setName($oneof_proto->getName());
+ foreach ($desc->getField() as $field) {
+ if ($field->getOneofIndex() == $index) {
+ $oneof->addField($field);
+ }
+ }
return $oneof;
}
}