Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Flag implements IteratorAggregate, Serializable
- {
- private $__bits = 0;
- public function __construct($mask = FALSE) { $this->__bits = is_string($mask) ? $this->convertBinDec($mask) : $this->convertInteger($mask); }
- public function __toString() { return $this->convertDecBin($this->__bits); }
- public function getIterator() { return new ArrayIterator($this->toArray()); }
- public function serialize() { return $this->convertString($this->__bits); }
- public function unserialize($serialized) { $this->__bits = $this->convertInteger($serialized); }
- public function get($offset) { $mask = 1 << $offset; return ($mask & $this->__bits) == $mask; }
- public function set($offset) { $this->__bits |= 1 << $offset; return $this; }
- public function reset($offset) { $this->__bits &= ~ (1 << $offset); return $this; }
- public function toggle($offset) { $this->__bits ^= 1 << $offset; return $this; }
- public function add($val) { $this->__bits |= $val; return $this; }
- public function remove($val) { $this->__bits &= ~ $val; return $this; }
- public function toString($max = FALSE) { return (!is_integer($max) ? $this->__toString() : str_pad( $this->__toString(), $max, 0, STR_PAD_LEFT)); }
- public function toArray() { return str_split(strrev($this->__toString())); }
- public function getNumeric() { return $this->__bits; }
- public function getHex() { return $this->convertHex($this->__bits); }
- public function getOct() { return $this->convertOct($this->__bits); }
- public function getBin() { return $this->convertBin($this->__bits); }
- private function convertBinDec($value) { return bindec($value); }
- private function convertDecBin($value) { return decbin($value); }
- private function convertInteger($value) { return intval($value); }
- private function convertString($value) { return strval($value); }
- private function convertHex($value) { return $this->convertBase($value, 16); }
- private function convertOct($value) { return $this->convertBase($value, 8); }
- private function convertBin($value) { return $this->convertBase($value, 2); }
- private function convertBase($value, $base) { return base_convert($value, $base, 10); }
- }
- class Type extends SystemObject
- {
- // 1 2 4 8 16 32 64 128 256 512 1024 2048 4096
- const iPrimitive = 0x00000000;
- const iModifiable = 0x00000001;
- const iObjectArray = 0x00000008;
- const iArrayAccess = 0x00000009;
- const iIterator = 0x0000000A;
- const iAggregate = 0x0000000B;
- const iCountable = 0x0000000C;
- const iSerializable = 0x0000000D;
- const iGenericTypeDefination = 0x0000000E;
- const iNested = 0x0000001F;
- private $__CONTEXT = NULL;
- private $__type = '';
- private static $__primitives = array('string' => TRUE, 'integer' => TRUE, 'boolean' => TRUE, 'float' => TRUE);
- public function __construct(SystemObject $object)
- {
- //if(!$object instanceOf Object)
- // ?? throw...
- $this->__type = get_class($object);
- $this->__CONTEXT = new Flag;
- $this->__CONTEXT->set(Type::iModifiable);
- if(isset(self::$__primitives[strtolower($this->__type)]))
- $this->__CONTEXT->set(Type::iPrimitive);
- if($object instanceOf ObjectArray) $this->__CONTEXT->set(Type::iObjectArray);
- if($object instanceOf ArrayAccess) $this->__CONTEXT->set(Type::iArrayAccess);
- if($object instanceOf Iterator) $this->__CONTEXT->set(Type::iIterator);
- if($object instanceOf IteratorAggregate) $this->__CONTEXT->set(Type::iAggregate);
- if($object instanceOf Countable) $this->__CONTEXT->set(Type::iCountable);
- if($object instanceOf Serializable) $this->__CONTEXT->set(Type::iSerializable);
- if($object instanceOf GenericTypeDefination) $this->__CONTEXT->set(Type::iGenericTypeDefination);
- if($object instanceOf Type) $this->__CONTEXT->set(Type::iNested);
- }
- public function getType() { return $this->__type; }
- public function isPrimitive() { return $this->__CONTEXT->get(Type::iPrimitive); }
- public function isModifiable() { return $this->__CONTEXT->get(Type::iModifiable); }
- public function isObjectArray() { return $this->__CONTEXT->get(Type::iObjectArray); }
- public function isArrayAccess() { return $this->__CONTEXT->get(Type::iArrayAccess); }
- public function isIterator() { return $this->__CONTEXT->get(Type::iIterator); }
- public function isAggregate() { return $this->__CONTEXT->get(Type::iAggregate); }
- public function isCountable() { return $this->__CONTEXT->get(Type::iCountable); }
- public function isSerializable() { return $this->__CONTEXT->get(Type::iCountable); }
- public function isGenericTypeDefination() { return $this->__CONTEXT->get(Type::iGenericTypeDefination); }
- public function isNested() { return $this->__CONTEXT->get(Type::iNested); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement