Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class System
- {
- const GC_COLLECT_CYCLES = 'gc_collect_cycles';
- public function finalize() { if(isset($__func_exists[self::GC_COLLECT_CYCLES])) gc_collect_cycles(); return $this; }
- public function isReference(Object $object) { /* how to check this? */ }
- final public function getHashCode() { return $this->internalHash()->getHashCode(); }
- public function __construct() { $this->setHashCode()->function_register(self::GC_COLLECT_CYCLES);}
- public function __destruct() { $this->finalize(); }
- private function setHashCode() { $this->__hash = new Hash(); return $this; }
- private function function_register($name) { if(!isset(self::$__func_checked[$name])){ self::$__func_checked[$name] = (bool) function_exists($name); if(TRUE === self::$__func_checked[$name]) self::$__func_exists[$name] = self::$__func_checked[$name];} }
- private $__hash = NULL;
- private static $__func_checked = array();
- private static $__func_exists = array();
- protected function internalHash() { return $this->__hash; }
- }
- final class Hash
- {
- public function getHashCode() { return new Integer($this->__hashCode); }
- public function __construct() { $this->__hashCode = mt_rand(); }
- private $__hashCode = NULL;
- }
- interface Type_Interface{}
- final class Type
- extends System
- implements Type_Interface
- {
- public function isArray() { return $this->__isArray; }
- public function isIterator() { return $this->__isIterator; }
- public function isCountable() { return $this->__isCountable; }
- public function isPrimitive() { return $this->__isPrimitive; }
- public function getType() { return $this->__type; }
- public function isLocked() { return $this->__isLocked; }
- public function lock() { $this->__isLocked = TRUE; return $this; }
- public function lockWithTrace() { $this->lock()->__locktrace = debug_backtrace(); return $this; }
- public function isModifiable() { if(TRUE === $this->isLocked()) throw new UnauthorizedAccessException(UnauthorizedAccessException::ERROR_LOCKED_FOR_MOD); return TRUE; }
- public function getLockTrace() { return $this->__locktrace; }
- public function __construct(SystemObject $value)
- {
- parent::__construct();
- $this->__type = get_class($value);
- $this->__isPrimitive = isset(self::$__primitives[strtolower($this->__type)]);
- $this->__isArray = ($value instanceOf ObjectArray);
- $this->__isCountable = ($value instanceOf COUNTABLE);
- $this->__isIterator = ($value instanceOf ITERATOR);
- }
- private static $__primitives = array('string' => TRUE, 'integer' => TRUE, 'boolean' => TRUE, 'float' => TRUE);
- private $__type = '';
- private $__isArray = NULL;
- private $__isPrimitive = NULL;
- private $__isCountable = NULL;
- private $__isIterator = NULL;
- private $__isLocked = FALSE;
- private $__locktrace = NULL;
- }
- interface Object_Interface
- {
- public function restore();
- public function apply();
- }
- abstract class SystemObject
- extends System
- {
- const Blank = NULL;
- final public function isArray() { return new Boolean($this->internalTypeIsArray()); }
- final public function isIterator() { return new Boolean($this->internalTypeIsIterator()); }
- final public function isCountable() { return new Boolean($this->internalTypeIsCountable()); }
- final public function isPrimitive() { return new Boolean($this->internalTypeIsPrimitive()); }
- final public function isModifiable() { return new Boolean($this->internalTypeIsModifiable()); }
- final public function getType() { return new String($this->internalTypeGetType()); }
- final public function lock() { $this->internalType()->lock(); return $this; }
- final public function lockWithTrace() { $this->internalType()->lockWithTrace(); return $this; }
- final public function toString() { return var_export($this)."\n"; }
- public function __construct() { parent::__construct(); $this->__type = new Type($this); }
- final private function internalType() { return $this->__type; }
- private $__type = NULL;
- final protected function internalTypeIsArray() { return $this->internalType()->isArray(); }
- final protected function internalTypeIsIterator() { return $this->internalType()->isIterator(); }
- final protected function internalTypeIsCountable() { return $this->internalType()->isCountable(); }
- final protected function internalTypeIsPrimitive() { return $this->internalType()->isPrimitive(); }
- final protected function internalTypeIsModifiable() { return $this->internalType()->isModifiable(); }
- final protected function internalTypeGetType() { return $this->internalType()->getType(); }
- final protected function _equals(SystemObject $object) { return new Boolean($this === $object); }
- }
- abstract class Object extends SystemObject implements Object_Interface
- {
- const Blank = NULL;
- final public function copy() { $copy = $this->getTemp(); $copy->set($this->__buffer); return $copy; }
- final public function duplicate() { $copy = $this->getTemp(); $copy->set($this->__buffer)->setCopy($this->__copy); return $copy; }
- final public function get() { return $this->__copy; }
- final public function restore() { $this->setCopy($this->__buffer); return $this; }
- final public function registerMember(Hash $hash) { $this->__usedBy[] = $hash->getHashCode()->get(); }
- public function set($value) { try{ if(FALSE === $this->internalTypeIsModifiable()) return $this; $this->__buffer = $value; return $this->setCopy($this->__buffer); } catch(UnauthorizedAccessException $e){throw new ObjectHandlerWriteException(ObjectHandlerWriteException::ERROR_CAN_NOT_WRITE, $e);} }
- final public function apply() { try{ if($this->internalTypeIsModifiable()) return $this->set($this->__copy); } catch(UnauthorizedAccessException $e){throw new ObjectHandlerWriteException(ObjectHandlerWriteException::ERROR_CAN_NOT_WRITE, $e);} }
- public function __construct($value) { parent::__construct(); $this->set($value); }
- private $__copy = self::Blank;
- private $__buffer = self::Blank;
- private $__usedBy = array();
- final protected function getTemp() { $c = get_class($this); return new $c($this->get()); }
- final protected function setCopy($value) { $this->__copy = $value; return $this; }
- final protected function _compareTo(Object $object) { return new Boolean($this->get() === $object->get()); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement