Enum.inc.php
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Base class for enumerators
*/
// TODO enable creation of enum instances on the fly - this will most likely be done in an extending class
abstract class Enum {
// actual implementation of these will be in child classes
static protected $name;
static protected $values;
static protected $value;
/**
* Sets the value of the enumerator
*
* @param unknown_type $value
* @throws invalidArgumentException if the given value does not match one of the allowed values
*
* Extending classes may override this function to add their own additional rules for how an enum may be set,
* but they should always call this parent function afterward to invoke the base rule that the value must be
* one of the defined values
*/
static protected function set($value)
{
if (!in_array($value, self::$values)) {
throw new InvalidArgumentException("Unable to set value for $name: Illegal input ($value)");
}
self::$value = $value;
}
/**
* Returns the currently set value, or null if unset
*
* @return $value the currently set value
*/
static protected function get()
{
return self::$value;
}
}
?>