diff options
Diffstat (limited to 'php/src/Google/Protobuf/Internal/FieldOptions/JSType.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/FieldOptions/JSType.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php b/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php index f7b78a1b3..5ff81620e 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions/JSType.php @@ -4,6 +4,8 @@ namespace Google\Protobuf\Internal\FieldOptions; +use UnexpectedValueException; + /** * Protobuf type <code>google.protobuf.FieldOptions.JSType</code> */ @@ -27,6 +29,31 @@ class JSType * Generated from protobuf enum <code>JS_NUMBER = 2;</code> */ const JS_NUMBER = 2; + + private static $valueToName = [ + self::JS_NORMAL => 'JS_NORMAL', + self::JS_STRING => 'JS_STRING', + self::JS_NUMBER => 'JS_NUMBER', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } } // Adding a class alias for backwards compatibility with the previous class name. |