8
8
* @author Petr Knap <dev@petrknap.cz>
9
9
* @since 2016-01-23
10
10
* @package PetrKnap\Php\Enum
11
- * @version 0.2
11
+ * @version 0.3
12
12
* @license https://github.com/petrknap/php-enum/blob/master/LICENSE MIT
13
13
*/
14
14
abstract class AbstractEnum
@@ -21,36 +21,36 @@ abstract class AbstractEnum
21
21
/**
22
22
* @var mixed[][]
23
23
*/
24
- private static $ constants = [];
24
+ private static $ members = [];
25
25
26
26
/**
27
- * @var mixed
27
+ * @var string
28
28
*/
29
- private $ constantName ;
29
+ private $ memberName ;
30
30
31
31
/**
32
32
* @var mixed
33
33
*/
34
- private $ constantValue ;
34
+ private $ memberValue ;
35
35
36
36
/**
37
- * @param mixed $constantName
37
+ * @param string $memberName
38
38
* @throws EnumException
39
39
*/
40
- protected function __construct ($ constantName )
40
+ protected function __construct ($ memberName )
41
41
{
42
- $ this ->constantName = $ constantName ;
43
- $ this ->constantValue = $ this ->get ($ constantName );
42
+ $ this ->memberName = $ memberName ;
43
+ $ this ->memberValue = $ this ->get ($ memberName );
44
44
}
45
45
46
46
/**
47
47
* Creates magical factories for easier access to enum
48
48
*
49
- * @param mixed $constantName enum key
49
+ * @param string $memberName enum key
50
50
* @param array $args ignored
51
51
* @return mixed
52
52
*/
53
- public static function __callStatic ($ constantName , array $ args )
53
+ public static function __callStatic ($ memberName , array $ args )
54
54
{
55
55
$ className = get_called_class ();
56
56
@@ -60,10 +60,10 @@ public static function __callStatic($constantName, array $args)
60
60
$ instances = [];
61
61
}
62
62
63
- $ instance = &$ instances [$ constantName ];
63
+ $ instance = &$ instances [$ memberName ];
64
64
65
65
if (!($ instance instanceof $ className )) {
66
- $ instance = new $ className ($ constantName );
66
+ $ instance = new $ className ($ memberName );
67
67
}
68
68
69
69
return $ instance ;
@@ -74,60 +74,60 @@ public static function __callStatic($constantName, array $args)
74
74
*/
75
75
public function getName ()
76
76
{
77
- return $ this ->constantName ;
77
+ return $ this ->memberName ;
78
78
}
79
79
80
80
/**
81
81
* @return mixed
82
82
*/
83
83
public function getValue ()
84
84
{
85
- return $ this ->constantValue ;
85
+ return $ this ->memberValue ;
86
86
}
87
87
88
88
/**
89
- * @param mixed[] $constants
89
+ * @param mixed[] $members
90
90
*/
91
- protected static function setConstants (array $ constants )
91
+ protected static function setMembers (array $ members )
92
92
{
93
- self ::$ constants [get_called_class ()] = $ constants ;
93
+ self ::$ members [get_called_class ()] = $ members ;
94
94
}
95
95
96
96
/**
97
97
* @return mixed[]
98
98
*/
99
- public static function getConstants ()
99
+ public static function getMembers ()
100
100
{
101
- return self ::$ constants [get_called_class ()];
101
+ return self ::$ members [get_called_class ()];
102
102
}
103
103
104
104
/**
105
- * @param string $constantName
105
+ * @param string $memberName
106
106
* @return bool
107
107
*/
108
- private function exists ($ constantName )
108
+ private function exists ($ memberName )
109
109
{
110
- return array_key_exists ($ constantName , self ::$ constants [get_called_class ()]);
110
+ return array_key_exists ($ memberName , self ::$ members [get_called_class ()]);
111
111
}
112
112
113
113
/**
114
- * @param string $constantName
114
+ * @param string $memberName
115
115
* @return mixed
116
116
* @throws EnumException
117
117
*/
118
- private function get ($ constantName )
118
+ private function get ($ memberName )
119
119
{
120
- if (!$ this ->exists ($ constantName )) {
120
+ if (!$ this ->exists ($ memberName )) {
121
121
throw new EnumException (
122
122
sprintf (
123
123
"%s does not exist in %s " ,
124
- $ constantName ,
124
+ $ memberName ,
125
125
get_called_class ()
126
126
),
127
127
EnumException::OUT_OF_RANGE
128
128
);
129
129
}
130
130
131
- return self ::$ constants [get_called_class ()][$ constantName ];
131
+ return self ::$ members [get_called_class ()][$ memberName ];
132
132
}
133
133
}
0 commit comments