• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?php
2# Generated by the protocol buffer compiler.  DO NOT EDIT!
3# source: google/protobuf/type.proto
4
5namespace Google\Protobuf\Field;
6
7use UnexpectedValueException;
8
9/**
10 * Whether a field is optional, required, or repeated.
11 *
12 * Protobuf type <code>google.protobuf.Field.Cardinality</code>
13 */
14class Cardinality
15{
16    /**
17     * For fields with unknown cardinality.
18     *
19     * Generated from protobuf enum <code>CARDINALITY_UNKNOWN = 0;</code>
20     */
21    const CARDINALITY_UNKNOWN = 0;
22    /**
23     * For optional fields.
24     *
25     * Generated from protobuf enum <code>CARDINALITY_OPTIONAL = 1;</code>
26     */
27    const CARDINALITY_OPTIONAL = 1;
28    /**
29     * For required fields. Proto2 syntax only.
30     *
31     * Generated from protobuf enum <code>CARDINALITY_REQUIRED = 2;</code>
32     */
33    const CARDINALITY_REQUIRED = 2;
34    /**
35     * For repeated fields.
36     *
37     * Generated from protobuf enum <code>CARDINALITY_REPEATED = 3;</code>
38     */
39    const CARDINALITY_REPEATED = 3;
40
41    private static $valueToName = [
42        self::CARDINALITY_UNKNOWN => 'CARDINALITY_UNKNOWN',
43        self::CARDINALITY_OPTIONAL => 'CARDINALITY_OPTIONAL',
44        self::CARDINALITY_REQUIRED => 'CARDINALITY_REQUIRED',
45        self::CARDINALITY_REPEATED => 'CARDINALITY_REPEATED',
46    ];
47
48    public static function name($value)
49    {
50        if (!isset(self::$valueToName[$value])) {
51            throw new UnexpectedValueException(sprintf(
52                    'Enum %s has no name defined for value %s', __CLASS__, $value));
53        }
54        return self::$valueToName[$value];
55    }
56
57    public static function value($name)
58    {
59        $const = __CLASS__ . '::' . strtoupper($name);
60        if (!defined($const)) {
61            throw new UnexpectedValueException(sprintf(
62                    'Enum %s has no value defined for name %s', __CLASS__, $name));
63        }
64        return constant($const);
65    }
66}
67
68// Adding a class alias for backwards compatibility with the previous class name.
69class_alias(Cardinality::class, \Google\Protobuf\Field_Cardinality::class);
70
71