@@ -128,7 +128,7 @@ final public function getOrdinal()
128
128
* @throws InvalidArgumentException On an unknwon or invalid value
129
129
* @throws LogicException On ambiguous constant values
130
130
*/
131
- static public function get ($ value )
131
+ final static public function get ($ value )
132
132
{
133
133
$ class = get_called_class ();
134
134
$ id = $ class . '. ' . $ value ;
@@ -141,6 +141,27 @@ static public function get($value)
141
141
return $ instance ;
142
142
}
143
143
144
+ /**
145
+ * Get an enum by the given ordinal number
146
+ *
147
+ * @param int $ordinal The ordinal number to instantiate the enum by
148
+ * @return Enum
149
+ * @throws InvalidArgumentException On an invalid ordinal number
150
+ * @throws LogicException On ambiguous constant values
151
+ */
152
+ final public static function getByOrdinal ($ ordinal )
153
+ {
154
+ $ constants = static ::getConstants ();
155
+ $ item = array_slice ($ constants , $ ordinal , 1 , false );
156
+ if (!$ item ) {
157
+ throw new InvalidArgumentException (sprintf (
158
+ 'Invalid ordinal number, must between 0 and %s ' ,
159
+ count ($ constants ) - 1
160
+ ));
161
+ }
162
+ return static ::get (current ($ item ));
163
+ }
164
+
144
165
/**
145
166
* Clears all instantiated enums
146
167
*
@@ -149,7 +170,7 @@ static public function get($value)
149
170
* @param null|string $class
150
171
* @return void
151
172
*/
152
- final static function clear ()
173
+ final static public function clear ()
153
174
{
154
175
$ class = get_called_class ();
155
176
@@ -214,6 +235,7 @@ final static public function getConstants()
214
235
*
215
236
* @param string $const The name of the constant to instantiate the enum with
216
237
* @param array $args There should be no arguments
238
+ * @return Enum
217
239
* @throws BadMethodCallException On an unknown constant name (method name)
218
240
* @throws LogicException On ambiguous constant values
219
241
*/
0 commit comments