File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,24 @@ final public static function getConstants()
267267 return self ::detectConstants (get_called_class ());
268268 }
269269
270+ /**
271+ * Check for given value
272+ *
273+ * @param static|null|bool|int|float|string $value
274+ * @return bool
275+ */
276+ final public static function has ($ value )
277+ {
278+ if ($ value instanceof static && get_class ($ value ) === get_called_class ()) {
279+ return true ;
280+ }
281+
282+ $ class = get_called_class ();
283+ $ constants = self ::detectConstants ($ class );
284+
285+ return in_array ($ value , $ constants , true );
286+ }
287+
270288 /**
271289 * Detect all available constants by the given class
272290 *
Original file line number Diff line number Diff line change @@ -245,4 +245,15 @@ public function testNotUnserializable()
245245 $ this ->setExpectedException ('LogicException ' );
246246 unserialize ("O:32: \"MabeEnumTest\TestAsset\EnumBasic \":0:{} " );
247247 }
248+
249+ public function testHas ()
250+ {
251+ $ enum = EnumBasic::ONE ();
252+
253+ $ this ->assertFalse ($ enum ->has ('invalid ' ));
254+ $ this ->assertFalse ($ enum ->has (EnumInheritance::ONE ()));
255+ $ this ->assertTrue ($ enum ->has (1 ));
256+ $ this ->assertTrue ($ enum ->has (EnumBasic::ONE ()));
257+ $ this ->assertTrue ($ enum ->has (EnumBasic::ONE ));
258+ }
248259}
You can’t perform that action at this time.
0 commit comments