SHOW:
|
|
- or go back to the newest paste.
| 1 | <?PHP | |
| 2 | /** | |
| 3 | * ILLI | |
| 4 | - | final public function __construct($default = self::__default) |
| 4 | + | * |
| 5 | * @category ILLI | |
| 6 | - | $this->__reflectionBase = new ReflectionClass(__CLASS__); |
| 6 | + | * @package ILLI |
| 7 | - | //$this->__reflectionClass = new ReflectionClass($this->getQualifiedName()); |
| 7 | + | * @subpackage SystemType |
| 8 | - | $this->__reflectionClass = new ReflectionClass(get_class($this)); |
| 8 | + | * @link http://illi.be |
| 9 | - | $this->__constantsBase = $this->__reflectionBase->getConstants(); |
| 9 | + | * @license http://l.illi.be |
| 10 | * @copyright ILLI Conference | |
| 11 | */ | |
| 12 | ||
| 13 | - | var_dump($this->__constantsBase); |
| 13 | + | /** |
| 14 | - | var_dump($this->__constantsClass); |
| 14 | + | * ILLI System Type Enum |
| 15 | - | /* |
| 15 | + | * |
| 16 | - | array(5) {
|
| 16 | + | * @category ILLI |
| 17 | - | ["__default"]=> |
| 17 | + | * @package ILLI |
| 18 | - | NULL |
| 18 | + | * @subpackage SystemType |
| 19 | - | ["__STRICT_INTEGER"]=> |
| 19 | + | * @link http://illi.be |
| 20 | - | int(1) |
| 20 | + | * @license http://l.illi.be |
| 21 | - | ["__STRICT_STRING"]=> |
| 21 | + | * @copyright ILLI Conference |
| 22 | - | int(2) |
| 22 | + | */ |
| 23 | - | ["__STRICT_FLOAT"]=> |
| 23 | + | ABSTRACT CLASS ILLI_System_Type_Enum EXTENDS ILLI_System_Type_Abstract |
| 24 | - | int(4) |
| 24 | + | {
|
| 25 | - | ["__STRICT_SCALAR"]=> |
| 25 | + | private static $__reflectionBase = NULL; |
| 26 | - | int(7) |
| 26 | + | private static $__constantsBase = array(); |
| 27 | - | } |
| 27 | + | |
| 28 | - | array(7) {
|
| 28 | + | private $__reflectionClass = NULL; |
| 29 | - | ["APPLE"]=> |
| 29 | + | private $__constantsClass = array(); |
| 30 | - | int(1) |
| 30 | + | |
| 31 | - | ["ORANGE"]=> |
| 31 | + | private $__definedConstants = NULL; |
| 32 | - | int(2) |
| 32 | + | |
| 33 | - | ["__default"]=> |
| 33 | + | private $__definedDefault = NULL; |
| 34 | - | NULL |
| 34 | + | private $__initValue = NULL; |
| 35 | - | ["__STRICT_INTEGER"]=> |
| 35 | + | private $__definedValue = NULL; |
| 36 | - | int(1) |
| 36 | + | |
| 37 | - | ["__STRICT_STRING"]=> |
| 37 | + | const STRICT_INTEGER = 0x00000001; |
| 38 | - | int(2) |
| 38 | + | const STRICT_STRING = 0x00000002; |
| 39 | - | ["__STRICT_FLOAT"]=> |
| 39 | + | const STRICT_FLOAT = 0x00000004; |
| 40 | - | int(4) |
| 40 | + | |
| 41 | - | ["__STRICT_SCALAR"]=> |
| 41 | + | const STRICT_SCALAR = 0x00000007; |
| 42 | - | int(7) |
| 42 | + | |
| 43 | - | } |
| 43 | + | |
| 44 | - | */ |
| 44 | + | const STRICT_TYPE = 0x00000001; |
| 45 | ||
| 46 | - | // remove private constants from child |
| 46 | + | private $mode = 0; |
| 47 | - | $diff = array_intersect_assoc($this->__constantsBase, $this->__constantsClass); |
| 47 | + | |
| 48 | ||
| 49 | final public function __construct($default = NULL) | |
| 50 | - | if($const == '__default') |
| 50 | + | |
| 51 | - | continue; |
| 51 | + | if(NULL === self::$__reflectionBase) |
| 52 | {
| |
| 53 | self::$__reflectionBase = new ReflectionClass(__CLASS__); | |
| 54 | self::$__constantsBase = self::$__reflectionBase->getConstants(); | |
| 55 | } | |
| 56 | - | var_dump($this->__constantsBase); |
| 56 | + | $this->__reflectionClass = new ReflectionClass($this->getQualifiedName()); |
| 57 | - | var_dump($this->__constantsClass); |
| 57 | + | |
| 58 | - | /* |
| 58 | + | |
| 59 | // hide constants from base | |
| 60 | - | array(5) {
|
| 60 | + | $diff = array_intersect_assoc(self::$__constantsBase, $this->__constantsClass); |
| 61 | - | ["__default"]=> |
| 61 | + | |
| 62 | - | NULL |
| 62 | + | |
| 63 | - | ["__STRICT_INTEGER"]=> |
| 63 | + | |
| 64 | - | int(1) |
| 64 | + | $this->__definedConstants = new ILLI_System_Type_AssocArray($this->__constantsClass); |
| 65 | - | ["__STRICT_STRING"]=> |
| 65 | + | |
| 66 | - | int(2) |
| 66 | + | if(sizeOf($this->__constantsClass) <= 1) |
| 67 | - | ["__STRICT_FLOAT"]=> |
| 67 | + | throw new ILLI_Exception_ArgumentExpected |
| 68 | - | int(4) |
| 68 | + | ( |
| 69 | - | ["__STRICT_SCALAR"]=> |
| 69 | + | ILLI_System_E::ARGUMENT_EXPECTED_ENUMERABLE_CONSTANT_EXPECTED, |
| 70 | - | int(7) |
| 70 | + | array($this->getQualifiedName()) |
| 71 | - | } |
| 71 | + | ); |
| 72 | - | array(3) {
|
| 72 | + | |
| 73 | - | ["APPLE"]=> |
| 73 | + | if(FALSE === $this->__definedConstants->offsetExists('__DEFAULT'))
|
| 74 | - | int(1) |
| 74 | + | throw new ILLI_Exception_ArgumentExpected |
| 75 | - | ["ORANGE"]=> |
| 75 | + | ( |
| 76 | - | int(2) |
| 76 | + | ILLI_System_E::ARGUMENT_EXPECTED_ENUMERABLE_DEFAULT_EXPECTED, |
| 77 | - | ["__default"]=> |
| 77 | + | array |
| 78 | - | NULL |
| 78 | + | ( |
| 79 | - | } |
| 79 | + | $this->getQualifiedName(), |
| 80 | - | */ |
| 80 | + | '__DEFAULT' |
| 81 | ) | |
| 82 | - | die(); |
| 82 | + | ); |
| 83 | ||
| 84 | $this->__definedDefault = $this->__definedConstants->offsetGet('__DEFAULT');
| |
| 85 | ||
| 86 | if(NULL === $this->__definedDefault) | |
| 87 | throw new ILLI_Exception_ArgumentExpected | |
| 88 | ( | |
| 89 | ILLI_System_E::ARGUMENT_EXPECTED_ENUMERABLE_IS_NULL, | |
| 90 | array | |
| 91 | ( | |
| 92 | $this->getQualifiedName(), | |
| 93 | '__DEFAULT' | |
| 94 | ) | |
| 95 | ); | |
| 96 | ||
| 97 | $this->__definedConstants->offsetUnset('__DEFAULT');
| |
| 98 | ||
| 99 | if(FALSE === $this->isDefinedValue($this->__definedDefault)) | |
| 100 | throw new ILLI_Exception_ArgumentExpected | |
| 101 | ( | |
| 102 | ILLI_SYSTEM_E::ARGUMENT_EXPECTED_ENUMERABLE_DEFINED_EXPECTED, | |
| 103 | array | |
| 104 | ( | |
| 105 | $this->getQualifiedName(), | |
| 106 | '__DEFAULT', | |
| 107 | $this->__definedDefault | |
| 108 | ) | |
| 109 | ); | |
| 110 | ||
| 111 | if(NULL === $default) | |
| 112 | $default = $this->__definedDefault; | |
| 113 | ||
| 114 | $this->define($default); | |
| 115 | $this->__initValue = $default; | |
| 116 | } | |
| 117 | ||
| 118 | final public function define($value) | |
| 119 | {
| |
| 120 | try | |
| 121 | {
| |
| 122 | if(FALSE === $this->isDefinedValue($value)) | |
| 123 | throw new ILLI_Exception_ArgumentOutOfRange | |
| 124 | ( | |
| 125 | ILLI_SYSTEM_E::ARGUMENT_OUT_OF_ENUM_INDEX, | |
| 126 | array($value) | |
| 127 | ); | |
| 128 | } | |
| 129 | catch(ILLI_Exception_ArgumentOutOfRange $e) | |
| 130 | {
| |
| 131 | throw $e; | |
| 132 | } | |
| 133 | catch(ILLI_Exception_Argument $e) | |
| 134 | {
| |
| 135 | throw new ILLI_Exception_ArgumentOutOfRange | |
| 136 | ( | |
| 137 | ILLI_SYSTEM_E::ARGUMENT_OUT_OF_ENUM_INDEX, | |
| 138 | $e, | |
| 139 | array($const) | |
| 140 | ); | |
| 141 | } | |
| 142 | ||
| 143 | $this->__definedValue = $value; | |
| 144 | } | |
| 145 | ||
| 146 | final public function getValues() | |
| 147 | {
| |
| 148 | return $this->__definedConstants->getValues(); | |
| 149 | } | |
| 150 | ||
| 151 | final public function getNames($value = NULL) | |
| 152 | {
| |
| 153 | return $this->__definedConstants->getOffsets($value); | |
| 154 | } | |
| 155 | ||
| 156 | final public function getValue($const) | |
| 157 | {
| |
| 158 | try | |
| 159 | {
| |
| 160 | if(FALSE === $this->isDefinedConst($const)) | |
| 161 | throw new ILLI_Exception_ArgumentOutOfRange | |
| 162 | ( | |
| 163 | ILLI_SYSTEM_E::ARGUMENT_OUT_OF_ENUM_INDEX, | |
| 164 | array($const) | |
| 165 | ); | |
| 166 | } | |
| 167 | catch(ILLI_Exception_ArgumentOutOfRange $e) | |
| 168 | {
| |
| 169 | throw $e; | |
| 170 | } | |
| 171 | catch(ILLI_Exception_Argument $e) | |
| 172 | {
| |
| 173 | throw new ILLI_Exception_ArgumentOutOfRange | |
| 174 | ( | |
| 175 | ILLI_SYSTEM_E::ARGUMENT_OUT_OF_ENUM_INDEX, | |
| 176 | $e, | |
| 177 | array($const) | |
| 178 | ); | |
| 179 | } | |
| 180 | ||
| 181 | return $this->__definedConstants->offsetGet($const); | |
| 182 | } | |
| 183 | ||
| 184 | final public function reset() | |
| 185 | {
| |
| 186 | $this->define($this->__initValue); | |
| 187 | } | |
| 188 | ||
| 189 | final public function getDefinedValue() | |
| 190 | {
| |
| 191 | return $this->__definedValue; | |
| 192 | } | |
| 193 | ||
| 194 | final public function getDefinedName() | |
| 195 | {
| |
| 196 | $res = $this->getDefinedNames(); | |
| 197 | return array_shift($res); | |
| 198 | } | |
| 199 | ||
| 200 | final public function getDefinedNames() | |
| 201 | {
| |
| 202 | return $this->getNames($this->__definedValue); | |
| 203 | } | |
| 204 | ||
| 205 | final public function getDefaultValue() | |
| 206 | {
| |
| 207 | return $this->__initValue; | |
| 208 | } | |
| 209 | ||
| 210 | final public function getDefaultName() | |
| 211 | {
| |
| 212 | $res = $this->getDefaultNames(); | |
| 213 | return array_shift($res); | |
| 214 | } | |
| 215 | ||
| 216 | final public function getDefaultNames() | |
| 217 | {
| |
| 218 | return $this->getNames($this->__initValue); | |
| 219 | } | |
| 220 | ||
| 221 | public function __toString() | |
| 222 | {
| |
| 223 | return (string) $this->getDefinedValue(); | |
| 224 | } | |
| 225 | ||
| 226 | public function __invoke() | |
| 227 | {
| |
| 228 | return $this->getDefinedValue(); | |
| 229 | } | |
| 230 | ||
| 231 | private function isDefinedValue($value) | |
| 232 | {
| |
| 233 | if(NULL === $value) | |
| 234 | throw new ILLI_Exception_ArgumentNull; | |
| 235 | ||
| 236 | if(!is_integer($value)) | |
| 237 | throw new ILLI_Exception_ArgumentExpected | |
| 238 | ( | |
| 239 | ILLI_System_E::ARGUMENT_EXPECTED_INTEGER | |
| 240 | ); | |
| 241 | ||
| 242 | foreach($this->__definedConstants as $key => $val) | |
| 243 | if($value === $val) | |
| 244 | return TRUE; | |
| 245 | ||
| 246 | return FALSE; | |
| 247 | } | |
| 248 | ||
| 249 | private function isDefinedConst($const) | |
| 250 | {
| |
| 251 | if(NULL === $const) | |
| 252 | throw new ILLI_Exception_ArgumentNull; | |
| 253 | ||
| 254 | if(!is_string($const)) | |
| 255 | throw new ILLI_Exception_ArgumentExpected | |
| 256 | ( | |
| 257 | ILLI_System_E::ARGUMENT_EXPECTED_STRING | |
| 258 | ); | |
| 259 | ||
| 260 | return $this->__definedConstants->offsetExists($const); | |
| 261 | } | |
| 262 | } |