• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?php
2
3// Protocol Buffers - Google's data interchange format
4// Copyright 2017 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;
11
12use Google\Protobuf\Internal\GetPublicDescriptorTrait;
13
14class OneofDescriptor
15{
16    use GetPublicDescriptorTrait;
17
18    /** @var  \Google\Protobuf\Internal\OneofDescriptor $internal_desc */
19    private $internal_desc;
20
21    /**
22     * @internal
23     */
24    public function __construct($internal_desc)
25    {
26        $this->internal_desc = $internal_desc;
27    }
28
29    /**
30     * @return string The name of the oneof
31     */
32    public function getName()
33    {
34        return $this->internal_desc->getName();
35    }
36
37    /**
38     * @param int $index Must be >= 0 and < getFieldCount()
39     * @return FieldDescriptor
40     */
41    public function getField($index)
42    {
43        if (
44            is_null($this->internal_desc->getFields())
45            || !isset($this->internal_desc->getFields()[$index])
46        ) {
47            return null;
48        }
49        return $this->getPublicDescriptor($this->internal_desc->getFields()[$index]);
50    }
51
52    /**
53     * @return int Number of fields in the oneof
54     */
55    public function getFieldCount()
56    {
57        return count($this->internal_desc->getFields());
58    }
59
60    public function isSynthetic()
61    {
62        return $this->internal_desc->isSynthetic();
63    }
64}
65