HH_IGNORE_ERROR All array literals in HHI files
[hiphop-php.git] / hphp / hack / hhi / BuiltinEnum.hhi
blob1feddc0cef6c9687786158f8e99bd1990dc88ac5
1 <?hh // decl
2 /**
3  * Copyright (c) 2014, Facebook, Inc.
4  * All rights reserved.
5  *
6  * This source code is licensed under the MIT license found in the
7  * LICENSE file in the "hack" directory of this source tree.
8  *
9  */
11 /**
12  * This file provides type information for some of HHVM's builtin classes.
13  *
14  * YOU SHOULD NEVER INCLUDE THIS FILE ANYWHERE!!!
15  */
16 namespace HH {
18 /**
19  * BuiltinEnum contains the utility methods provided by enums.
20  * Under the hood, an enum Foo will extend BuiltinEnum<Foo>.
21  *
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.
25  */
26 abstract class BuiltinEnum<T> {
27   /**
28    * Get the values of the public consts defined on this class,
29    * indexed by the string name of those consts.
30    *
31    * @return array ('CONST_NAME' => $value, ....)
32    */
33   <<__Rx>>
34   final public static function getValues(): array<string, T>;
36   /**
37    * Get the names of all the const values, indexed by value. Calls
38    * invariant_exception if multiple constants have the same value.
39    *
40    * @return array($value => 'CONST_NAME', ....)
41    */
42   <<__Rx>>
43   final public static function getNames(): array<T, string>;
45   /**
46    * Returns whether or not the value is defined as a constant.
47    */
48   <<__Rx>>
49   final public static function isValid(mixed $value): bool;
51   /**
52    * Coerce to a valid value or null.
53    * This is useful for typing deserialized enum values.
54    */
55   <<__Rx>>
56   final public static function coerce(mixed $value): ?T;
58   /**
59    * Coerce to valid value or throw UnexpectedValueException
60    * This is useful for typing deserialized enum values.
61    */
62   <<__Rx>>
63   final public static function assert(mixed $value): T;
65   /**
66    * Coerce all the values in a traversable. If the value is not an
67    * array of valid items, an UnexpectedValueException is thrown
68    */
69   <<__Rx>>
70   final public static function assertAll(
71     Traversable<mixed> $values,
72   ): Container<T>;