Enum.inc.php
964 Bytes
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
<?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 private $values;
static private $value;
static private $name;
/**
* Sets the value of the enumerator
*
* @param unknown_type $value
* @throws invalidArgumentException if the given value does not match one of the allowed 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
*
*/
static protected function get()
{
return self::$value;
}
}
?>