@@ -141,6 +141,24 @@ final static public function get($value)
141
141
return $ instance ;
142
142
}
143
143
144
+ /**
145
+ * Get an enum by the given name
146
+ *
147
+ * @param string $name The name to instantiate the enum by
148
+ * @return Enum
149
+ * @throws InvalidArgumentException On an invalid or unknown name
150
+ * @throws LogicException On ambiguous constant values
151
+ */
152
+ final public static function getByName ($ name )
153
+ {
154
+ $ classConst = 'static:: ' . $ name ;
155
+ if (!defined ($ classConst )) {
156
+ $ class = get_called_class ();
157
+ throw new InvalidArgumentException ($ class . ':: ' . $ name . ' not defined ' );
158
+ }
159
+ return static ::get (constant ($ classConst ));
160
+ }
161
+
144
162
/**
145
163
* Get an enum by the given ordinal number
146
164
*
@@ -233,19 +251,14 @@ final static public function getConstants()
233
251
* This will be called automatically on calling a method
234
252
* with the same name of a defined constant.
235
253
*
236
- * @param string $const The name of the constant to instantiate the enum with
237
- * @param array $args There should be no arguments
254
+ * @param string $method The name to instantiate the enum by (called as method)
255
+ * @param array $args There should be no arguments
238
256
* @return Enum
239
- * @throws BadMethodCallException On an unknown constant name (method name)
240
- * @throws LogicException On ambiguous constant values
257
+ * @throws InvalidArgumentException On an invalid or unknown name
258
+ * @throws LogicException On ambiguous constant values
241
259
*/
242
- final public static function __callStatic ($ const , array $ args )
260
+ final public static function __callStatic ($ method , array $ args )
243
261
{
244
- $ classConst = 'static:: ' . $ const ;
245
- if (!defined ($ classConst )) {
246
- $ class = get_called_class ();
247
- throw new BadMethodCallException ($ class . ':: ' . $ const . ' not defined ' );
248
- }
249
- return static ::get (constant ($ classConst ));
262
+ return static ::getByName ($ method );
250
263
}
251
264
}
0 commit comments