3 * Copyright (c) 2014, Facebook, Inc.
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the "hack" directory of this source tree.
12 * This file provides type information for some of HHVM's builtin classes.
14 * YOU SHOULD NEVER INCLUDE THIS FILE ANYWHERE!!!
19 * BuiltinEnum contains the utility methods provided by enums.
20 * Under the hood, an enum Foo will extend BuiltinEnum<Foo>.
22 * HHVM provides a native implementation for this class. The PHP class
23 * definition below is not actually used at run time; it is simply
24 * provided for the typechecker and for developer reference.
26 abstract class BuiltinEnum<T> {
28 * Get the values of the public consts defined on this class,
29 * indexed by the string name of those consts.
31 * @return array ('CONST_NAME' => $value, ....)
34 final public static function getValues(): array<string, T>;
37 * Get the names of all the const values, indexed by value. Calls
38 * invariant_exception if multiple constants have the same value.
40 * @return array($value => 'CONST_NAME', ....)
43 final public static function getNames(): array<T, string>;
46 * Returns whether or not the value is defined as a constant.
49 final public static function isValid(mixed $value): bool;
52 * Coerce to a valid value or null.
53 * This is useful for typing deserialized enum values.
56 final public static function coerce(mixed $value): ?T;
59 * Coerce to valid value or throw UnexpectedValueException
60 * This is useful for typing deserialized enum values.
63 final public static function assert(mixed $value): T;
66 * Coerce all the values in a traversable. If the value is not an
67 * array of valid items, an UnexpectedValueException is thrown
70 final public static function assertAll(
71 Traversable<mixed> $values,