@@ -62,10 +62,10 @@ class EnumMap extends SplObjectStorage
62
62
const CURRENT_AS_ORDINAL = 40 ;
63
63
64
64
/**
65
- * The classname of an enumeration this map is for
65
+ * The classname of the enumeration type
66
66
* @var string
67
67
*/
68
- private $ enumClass ;
68
+ private $ enumeration ;
69
69
70
70
/**
71
71
* Flags to define behaviors
@@ -76,32 +76,42 @@ class EnumMap extends SplObjectStorage
76
76
77
77
/**
78
78
* Constructor
79
- * @param string $enumClass The classname of an enumeration the map is for
80
- * @param int|null $flags Behaviour flags, see KEY_AS_* and CURRENT_AS_* constants
79
+ * @param string $enumeration The classname of the enumeration type
80
+ * @param int|null $flags Behaviour flags, see KEY_AS_* and CURRENT_AS_* constants
81
81
* @throws InvalidArgumentException
82
82
*/
83
- public function __construct ($ enumClass , $ flags = null )
83
+ public function __construct ($ enumeration , $ flags = null )
84
84
{
85
- if (!is_subclass_of ($ enumClass , __NAMESPACE__ . '\Enum ' )) {
85
+ if (!is_subclass_of ($ enumeration , __NAMESPACE__ . '\Enum ' )) {
86
86
throw new InvalidArgumentException (sprintf (
87
87
"This EnumMap can handle subclasses of '%s' only " ,
88
88
__NAMESPACE__ . '\Enum '
89
89
));
90
90
}
91
- $ this ->enumClass = $ enumClass ;
91
+ $ this ->enumeration = $ enumeration ;
92
92
93
93
if ($ flags !== null ) {
94
94
$ this ->setFlags ($ flags );
95
95
}
96
96
}
97
97
98
98
/**
99
- * Get the classname of the enumeration this map is for
99
+ * Get the classname of the enumeration
100
100
* @return string
101
+ * @deprecated Please use getEnumeration() instead
101
102
*/
102
103
public function getEnumClass ()
103
104
{
104
- return $ this ->enumClass ;
105
+ return $ this ->getEnumeration ();
106
+ }
107
+
108
+ /**
109
+ * Get the classname of the enumeration
110
+ * @return string
111
+ */
112
+ public function getEnumeration ()
113
+ {
114
+ return $ this ->enumeration ;
105
115
}
106
116
107
117
/**
@@ -147,27 +157,27 @@ public function getFlags()
147
157
148
158
/**
149
159
* Attach a new enumerator or overwrite an existing one
150
- * @param Enum|null|boolean|int|float|string $enum
160
+ * @param Enum|null|boolean|int|float|string $enumerator
151
161
* @param mixed $data
152
162
* @return void
153
- * @throws InvalidArgumentException On an invalid given enum
163
+ * @throws InvalidArgumentException On an invalid given enumerator
154
164
*/
155
- public function attach ($ enum , $ data = null )
165
+ public function attach ($ enumerator , $ data = null )
156
166
{
157
- $ enumClass = $ this ->enumClass ;
158
- parent ::attach ($ enumClass ::get ($ enum ), $ data );
167
+ $ enumeration = $ this ->enumeration ;
168
+ parent ::attach ($ enumeration ::get ($ enumerator ), $ data );
159
169
}
160
170
161
171
/**
162
172
* Test if the given enumerator exists
163
- * @param Enum|null|boolean|int|float|string $enum
173
+ * @param Enum|null|boolean|int|float|string $enumerator
164
174
* @return boolean
165
175
*/
166
- public function contains ($ enum )
176
+ public function contains ($ enumerator )
167
177
{
168
178
try {
169
- $ enumClass = $ this ->enumClass ;
170
- return parent ::contains ($ enumClass ::get ($ enum ));
179
+ $ enumeration = $ this ->enumeration ;
180
+ return parent ::contains ($ enumeration ::get ($ enumerator ));
171
181
} catch (InvalidArgumentException $ e ) {
172
182
// On an InvalidArgumentException the given argument can't be contained in this map
173
183
return false ;
@@ -176,77 +186,77 @@ public function contains($enum)
176
186
177
187
/**
178
188
* Detach an enumerator
179
- * @param Enum|null|boolean|int|float|string $enum
189
+ * @param Enum|null|boolean|int|float|string $enumerator
180
190
* @return void
181
- * @throws InvalidArgumentException On an invalid given enum
191
+ * @throws InvalidArgumentException On an invalid given enumerator
182
192
*/
183
- public function detach ($ enum )
193
+ public function detach ($ enumerator )
184
194
{
185
- $ enumClass = $ this ->enumClass ;
186
- parent ::detach ($ enumClass ::get ($ enum ));
195
+ $ enumeration = $ this ->enumeration ;
196
+ parent ::detach ($ enumeration ::get ($ enumerator ));
187
197
}
188
198
189
199
/**
190
200
* Get a unique identifier for the given enumerator
191
- * @param Enum|scalar $enum
201
+ * @param Enum|scalar $enumerator
192
202
* @return string
193
- * @throws InvalidArgumentException On an invalid given enum
203
+ * @throws InvalidArgumentException On an invalid given enumerator
194
204
*/
195
- public function getHash ($ enum )
205
+ public function getHash ($ enumerator )
196
206
{
197
207
// getHash is available since PHP 5.4
198
- $ enumClass = $ this ->enumClass ;
199
- return spl_object_hash ($ enumClass ::get ($ enum ));
208
+ $ enumeration = $ this ->enumeration ;
209
+ return spl_object_hash ($ enumeration ::get ($ enumerator ));
200
210
}
201
211
202
212
/**
203
213
* Test if the given enumerator exists
204
- * @param Enum|null|boolean|int|float|string $enum
214
+ * @param Enum|null|boolean|int|float|string $enumerator
205
215
* @return boolean
206
216
* @see contains()
207
217
*/
208
- public function offsetExists ($ enum )
218
+ public function offsetExists ($ enumerator )
209
219
{
210
- return $ this ->contains ($ enum );
220
+ return $ this ->contains ($ enumerator );
211
221
}
212
222
213
223
/**
214
224
* Get mapped data for the given enumerator
215
- * @param Enum|null|boolean|int|float|string $enum
225
+ * @param Enum|null|boolean|int|float|string $enumerator
216
226
* @return mixed
217
- * @throws InvalidArgumentException On an invalid given enum
227
+ * @throws InvalidArgumentException On an invalid given enumerator
218
228
*/
219
- public function offsetGet ($ enum )
229
+ public function offsetGet ($ enumerator )
220
230
{
221
- $ enumClass = $ this ->enumClass ;
222
- return parent ::offsetGet ($ enumClass ::get ($ enum ));
231
+ $ enumeration = $ this ->enumeration ;
232
+ return parent ::offsetGet ($ enumeration ::get ($ enumerator ));
223
233
}
224
234
225
235
/**
226
236
* Attach a new enumerator or overwrite an existing one
227
- * @param Enum|null|boolean|int|float|string $enum
237
+ * @param Enum|null|boolean|int|float|string $enumerator
228
238
* @param mixed $data
229
239
* @return void
230
- * @throws InvalidArgumentException On an invalid given enum
240
+ * @throws InvalidArgumentException On an invalid given enumerator
231
241
* @see attach()
232
242
*/
233
- public function offsetSet ($ enum , $ data = null )
243
+ public function offsetSet ($ enumerator , $ data = null )
234
244
{
235
- $ enumClass = $ this ->enumClass ;
236
- parent ::offsetSet ($ enumClass ::get ($ enum ), $ data );
245
+ $ enumeration = $ this ->enumeration ;
246
+ parent ::offsetSet ($ enumeration ::get ($ enumerator ), $ data );
237
247
}
238
248
239
249
/**
240
250
* Detach an existing enumerator
241
- * @param Enum|null|boolean|int|float|string $enum
251
+ * @param Enum|null|boolean|int|float|string $enumerator
242
252
* @return void
243
- * @throws InvalidArgumentException On an invalid given enum
253
+ * @throws InvalidArgumentException On an invalid given enumerator
244
254
* @see detach()
245
255
*/
246
- public function offsetUnset ($ enum )
256
+ public function offsetUnset ($ enumerator )
247
257
{
248
- $ enumClass = $ this ->enumClass ;
249
- parent ::offsetUnset ($ enumClass ::get ($ enum ));
258
+ $ enumeration = $ this ->enumeration ;
259
+ parent ::offsetUnset ($ enumeration ::get ($ enumerator ));
250
260
}
251
261
252
262
/**
0 commit comments