1 | <?php |
||
13 | abstract class Enum |
||
14 | { |
||
15 | protected $value; |
||
16 | |||
17 | /** |
||
18 | * Return string representation of this enum |
||
19 | * |
||
20 | * @return integer |
||
21 | */ |
||
22 | public function getValue() |
||
26 | |||
27 | /** |
||
28 | * Tries to set the value of this enum |
||
29 | * |
||
30 | * @param int $value |
||
31 | * @throws Exception If value is not part of this enum |
||
32 | */ |
||
33 | public function setValue($value) |
||
41 | |||
42 | /** |
||
43 | * Validates if the type given is part of this enum class |
||
44 | * |
||
45 | * @param string $checkValue |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function isValidEnumValue($checkValue) |
||
58 | |||
59 | /** |
||
60 | * @param string $value Value for this display type |
||
61 | */ |
||
62 | public function __construct($value) |
||
66 | |||
67 | /** |
||
68 | * With a magic getter you can get the value from this enum using |
||
69 | * any variable name as in: |
||
70 | * |
||
71 | * <code> |
||
72 | * $myEnum = new MyEnum(MyEnum::start); |
||
73 | * echo $myEnum->v; |
||
74 | * </code> |
||
75 | * |
||
76 | * @param string $property |
||
77 | * @return integer |
||
78 | */ |
||
79 | public function __get($property) |
||
83 | |||
84 | /** |
||
85 | * With a magic setter you can set the enum value using any variable |
||
86 | * name as in: |
||
87 | * |
||
88 | * <code> |
||
89 | * $myEnum = new MyEnum(MyEnum::Start); |
||
90 | * $myEnum->v = MyEnum::End; |
||
91 | * </code> |
||
92 | * |
||
93 | * @param string $property |
||
94 | * @param string $value |
||
95 | * @throws Exception Throws exception if an invalid type is used |
||
96 | */ |
||
97 | public function __set($property, $value) |
||
101 | |||
102 | /** |
||
103 | * If the enum is requested as a string then this function will be automatically |
||
104 | * called and the value of this enum will be returned as a string. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function __toString() |
||
112 | } |
||
113 | } |
||
114 |