File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Pdsinterop \Solid \Auth \Enum ;
4+
5+ use ReflectionClass ;
6+
7+ abstract class AbstractEnum
8+ {
9+ ////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
10+
11+ private static $ instance ;
12+
13+ //////////////////////////// GETTERS AND SETTERS \\\\\\\\\\\\\\\\\\\\\\\\\\\
14+
15+ private static function getInstance () : AbstractEnum
16+ {
17+ $ classname = static ::class;
18+
19+ if (self ::$ instance [$ classname ] === null ) {
20+ self ::$ instance [$ classname ] = new $ classname ;
21+ }
22+
23+ return self ::$ instance [$ classname ];
24+ }
25+
26+ final public function getValues () : array
27+ {
28+ static $ values ;
29+
30+ if ($ values === null ) {
31+ $ reflectionClass = new ReflectionClass (static ::class);
32+
33+ $ values = array_values ($ reflectionClass ->getConstants ());
34+
35+ natcasesort ($ values );
36+ }
37+
38+ return $ values ;
39+ }
40+
41+ //////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
42+
43+ final public static function has ($ value ) : bool
44+ {
45+ return self ::getInstance ()->hasValue ($ value );
46+ }
47+
48+ final public function hasValue ($ value ) : bool
49+ {
50+ return in_array ($ value , $ this ->getValues (), true );
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments