File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,27 @@ final public static function getConstants()
258
258
return self ::detectConstants (get_called_class ());
259
259
}
260
260
261
+ /**
262
+ * Check for given value
263
+ *
264
+ * @param static|null|bool|int|float|string $value
265
+ * @return bool
266
+ */
267
+ final public static function has ($ value )
268
+ {
269
+ if ($ value instanceof static) {
270
+ if (get_class ($ value ) === get_called_class ()) {
271
+ return true ;
272
+ }
273
+ $ value = $ value ->getValue ();
274
+ }
275
+
276
+ $ class = get_called_class ();
277
+ $ constants = self ::detectConstants ($ class );
278
+
279
+ return in_array ($ value , $ constants , true );
280
+ }
281
+
261
282
/**
262
283
* Detect constants available by given class
263
284
*
Original file line number Diff line number Diff line change @@ -238,4 +238,13 @@ public function testNotUnserializable()
238
238
$ this ->setExpectedException ('LogicException ' );
239
239
unserialize ("O:32: \"MabeEnumTest\TestAsset\EnumBasic \":0:{} " );
240
240
}
241
+
242
+ public function testHas ()
243
+ {
244
+ $ enum = EnumBasic::ONE ();
245
+ $ this ->assertFalse ($ enum ->has ('invalid ' ));
246
+ $ this ->assertTrue ($ enum ->has (EnumInheritance::ONE ()));
247
+ $ this ->assertTrue ($ enum ->has (EnumBasic::ONE ()));
248
+ $ this ->assertTrue ($ enum ->has (EnumBasic::ONE ));
249
+ }
241
250
}
You can’t perform that action at this time.
0 commit comments