@@ -35,21 +35,44 @@ public static function create($id)
35
35
36
36
public function __construct ($ id )
37
37
{
38
- $ this ->setId ($ id );
38
+ $ this ->setInternalId ($ id );
39
39
}
40
40
41
- /// prevent's serialization of names' array
42
- //@{
41
+ /**
42
+ * @param $id
43
+ * @return Enum
44
+ * @throws MissingElementException
45
+ */
46
+ protected function setInternalId ($ id )
47
+ {
48
+ $ names = static ::$ names ;
49
+
50
+ if (isset ($ names [$ id ])) {
51
+ $ this ->id = $ id ;
52
+ $ this ->name = $ names [$ id ];
53
+ } else
54
+ throw new MissingElementException (
55
+ 'knows nothing about such id == ' .$ id
56
+ );
57
+
58
+ return $ this ;
59
+ }
60
+
61
+ /**
62
+ * @return string
63
+ */
43
64
public function serialize ()
44
65
{
45
66
return (string ) $ this ->id ;
46
67
}
47
68
69
+ /**
70
+ * @param $serialized
71
+ */
48
72
public function unserialize ($ serialized )
49
73
{
50
- $ this ->setId ($ serialized );
74
+ $ this ->setInternalId ($ serialized );
51
75
}
52
- //@}
53
76
54
77
/**
55
78
* Array of object
@@ -68,13 +91,16 @@ public static function getList()
68
91
/**
69
92
* must return any existent ID
70
93
* 1 should be ok for most enumerations
94
+ * @return integer
71
95
**/
72
96
public static function getAnyId ()
73
97
{
74
98
return 1 ;
75
99
}
76
100
77
- /// parent's getId() is too complex in our case
101
+ /**
102
+ * @return null|integer
103
+ */
78
104
public function getId ()
79
105
{
80
106
return $ this ->id ;
@@ -92,11 +118,19 @@ public static function getObjectList()
92
118
return static ::getList ();
93
119
}
94
120
121
+ /**
122
+ * @return string
123
+ */
95
124
public function toString ()
96
125
{
97
126
return $ this ->name ;
98
127
}
99
128
129
+ /**
130
+ * Plain list
131
+ * @static
132
+ * @return array
133
+ */
100
134
public static function getNameList ()
101
135
{
102
136
return static ::$ names ;
@@ -107,17 +141,7 @@ public static function getNameList()
107
141
**/
108
142
public function setId ($ id )
109
143
{
110
- $ names = static ::$ names ;
111
-
112
- if (isset ($ names [$ id ])) {
113
- $ this ->id = $ id ;
114
- $ this ->name = $ names [$ id ];
115
- } else
116
- throw new MissingElementException (
117
- 'knows nothing about such id == ' .$ id
118
- );
119
-
120
- return $ this ;
144
+ throw new UnsupportedMethodException ('You can not change id here, because it is politics for Enum! ' );
121
145
}
122
146
}
123
147
?>
0 commit comments