Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- //error_reporting(E_ALL|E_STRICT);
- require_once 'exception.php';
- //header('Content-Type: text/plain');
- 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 isArrayObject() { return $this->__isArrayObject; }
- public function isArrayAccess() { return $this->__isArrayAccess; }
- 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->__isArrayObject = ($value instanceOf ObjectArray);
- $this->__isCountable = ($value instanceOf COUNTABLE);
- $this->__isIterator = ($value instanceOf ITERATOR);
- $this->__isArrayAccess = ($value instanceOf ARRAYACCESS);
- }
- private static $__primitives = array('string' => TRUE, 'integer' => TRUE, 'boolean' => TRUE, 'float' => TRUE);
- private $__type = '';
- private $__isArrayObject = NULL;
- private $__isArrayAccess = 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()); }
- }
- interface String_Interface
- {
- public function toUpper();
- public function toLower();
- public function length();
- public function compareTo(String $string, Boolean $casesensitive = NULL);
- public function trim(String $replace = NULL);
- public function trimStart(String $replace = NULL);
- public function trimEnd(String $replace = NULL);
- public function joinLeft(String $string, String $separator = NULL);
- public function joinRight(String $string, String $separator = NULL);
- public function insert(Integer $start, String $string);
- public function padLeft(Integer $chars, String $string = NULL);
- public function padRight(Integer $chars, String $string = NULL);
- public function contains(String $string, Boolean $casesensitive = NULL);
- public function endsWith(String $string, Boolean $casesensitive = NULL);
- public function startsWith(String $string, Boolean $casesensitive = NULL);
- public function indexOf(String $string, Boolean $casesensitive = NULL);
- public function lastIndexOf(String $string, Boolean $casesensitive = NULL);
- public function replace(String $search, String $replace = NULL);
- public function split(String $string = NULL);
- public function remove(Integer $start, Integer $length = NULL);
- }
- class String extends Object implements String_Interface
- {
- const Blank = '';
- public function equals(String $string) { return parent::_equals($string); }
- public function isUtf8() { $value = $this->get(); return new Boolean((bool) (utf8_encode(utf8_decode($value)) == $value)); }
- public function isEmpty() { $value = $this->get(); return new Boolean((bool) empty($value)); }
- public function isWhitespace() { $value = trim($this->get(), ' '); return new Boolean((bool) empty($value)); }
- public function length() { return new Integer(strlen($this->get())); }
- public function toUpper() { return $this->setCopy(strtoupper($this->get())); }
- public function toLower() { return $this->setCopy(strtolower($this->get())); }
- public function toBoolean() { return new Boolean((bool) $this->get()); }
- public function set($value)
- {
- if(NULL === $value) throw new ArgumentNullException;
- if(!is_string($value)) throw new DatatypeExpectedException(DatatypeExpectedException::ERROR_NOT_STRING);
- parent::set((string) $value);
- return $this;
- }
- public function compareTo(String $string, Boolean $casesensitive = NULL)
- {
- return new Boolean(($casesensitive === NULL || $casesensitive->get() === FALSE)
- ? ($this->get() === $string->get())
- : ($this->getTemp()->toLower()->get() === $string->getTemp()->toLower()->get()));
- }
- public function trim(String $replace = NULL)
- {
- return $this->setCopy(($replace === NULL || TRUE === $replace->isEmpty())
- ? trim($this->get())
- : trim($this->get(), $replace->get()));
- }
- public function trimStart(String $replace = NULL)
- {
- return $this->setCopy(($replace === NULL || TRUE === $replace->isEmpty())
- ? ltrim($this->get())
- : ltrim($this->get(), $replace->get()));
- }
- public function trimEnd(String $replace = NULL)
- {
- return $this->setCopy(($replace === NULL || TRUE === $replace->isEmpty())
- ? rtrim($this->get())
- : rtrim($this->get(), $replace->get()));
- }
- public function join(String $string)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return $this->setCopy(implode($string->get(), preg_split('/(?<!^)(?!$)/u', $this->get())));
- }
- public function joinLeft(String $string, String $separator = NULL)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return $this->setCopy(($separator === NULL)
- ? ($string->get().$this->get())
- : ($string->get().$separator->get().$this->get()));
- }
- public function joinRight(String $string, String $separator = NULL)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return $this->setCopy(($separator === NULL)
- ? ($this->get().$string->get())
- : ($this->get().$separator->get().$string->get()));
- }
- public function insert(Integer $start, String $string)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- try{if($start->get() < 0) throw new ArgumentOutOfRangeException(ArgumentOutOfRangeException::ERROR_OUT_OF_STRING_INDEX);}
- catch(ArgumentOutOfRangeException $e){ throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_NOT_POSITIVE_INTEGER_OR_ZERO, $e);}
- $value = $this->get();
- return $this->setCopy(substr($value, 0, $start->get() ).$string->get().substr($value, $start->get(), $this->length()->get()));
- }
- /**
- * @todo str_pad is fuzzy. rewrite this
- */
- public function padLeft(Integer $chars, String $string = NULL)
- {
- try{if($chars->get() < 0) throw new ArgumentOutOfRangeException(ArgumentOutOfRangeException::ERROR_OUT_OF_STRING_INDEX);}
- catch(ArgumentOutOfRangeException $e){ throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_NOT_POSITIVE_INTEGER_OR_ZERO, $e);}
- return $this->setCopy(($string === NULL || $string->isEmpty()->get() === TRUE)
- ? (str_pad($this->get(), $chars->get(), ' ', STR_PAD_LEFT))
- : (str_pad($this->get(), $chars->get(), $string->get(), STR_PAD_LEFT)));
- }
- /**
- * @todo str_pad is fuzzy. rewrite this
- */
- public function padRight(Integer $chars, String $string = NULL)
- {
- try{if($chars->get() < 0) throw new ArgumentOutOfRangeException(ArgumentOutOfRangeException::ERROR_OUT_OF_STRING_INDEX);}
- catch(ArgumentOutOfRangeException $e){ throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_NOT_POSITIVE_INTEGER_OR_ZERO, $e);}
- return $this->setCopy(($string === NULL || $string->isEmpty()->get() === TRUE)
- ? (str_pad($this->get(), $chars->get(), ' ', STR_PAD_RIGHT))
- : (str_pad($this->get(), $chars->get(), $string->get(), STR_PAD_RIGHT)));
- }
- public function contains(String $string, Boolean $casesensitive = NULL)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return new Boolean((bool)(($casesensitive === NULL || $casesensitive->get() === FALSE)
- ? (preg_match('#'.$string->get().'#msie', $this->get()))
- : (preg_match('#'.$string->get().'#mse', $this->get()))));
- }
- public function endsWith(String $string, Boolean $casesensitive = NULL)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return new Boolean((bool)(($casesensitive === NULL || $casesensitive->get() === FALSE)
- ? ($string->get() == substr($this->get(), $this->length()->get() - $string->length()->get() ))
- : ($string->getTemp()->toLower()->get() == substr($this->getTemp()->toLower()->get(), $this->length()->get() - $string->length()->get() ))));
- }
- public function startsWith(String $string, Boolean $casesensitive = NULL)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return new Boolean((bool)(($casesensitive === NULL || $casesensitive->get() === FALSE)
- ? ($string->get() == substr($this->get(), 0, $string->length()->get()))
- : ($string->getTemp()->toLower()->get() == substr($this->getTemp()->toLower()->get(), 0, $string->length()->get()))));
- }
- /**
- * @todo returns IntegerArray. how to map the results?
- */
- public function indexOf(String $string, Boolean $casesensitive = NULL)
- {
- throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED);
- }
- public function lastIndexOf(String $string, Boolean $casesensitive = NULL)
- {
- if(TRUE === $string->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- $result = ($casesensitive === NULL || $casesensitive->get() === FALSE)
- ? (strrpos($this->get(), $string->get()))
- : (strrpos($this->getTemp()->toLower()->get(), $string->getTemp()->toLower()->get()));
- try{ return new Integer($result); }
- catch(DatatypeExpectedException $e){ return new Boolean($result); }
- }
- public function replace(String $search, String $replace = NULL)
- {
- if(TRUE === $search->isEmpty()->get()) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- return $this->setCopy(($replace === NULL || $replace->isEmpty() === TRUE)
- ? (str_replace($search->get(), '', $this->get()))
- : (str_replace($search->get(), $replace->get(), $this->get())));
- }
- /**
- * @todo check split-pattern
- */
- public function split(String $string = NULL)
- {
- return new StringArray(($string === NULL || $string->isEmpty()->get() === TRUE)
- ? (preg_split('/(?<!^)(?!$)/u', $this->get()))
- : (explode($string->get(), $this->get())));
- }
- /**
- * @todo returns IntegerArray. how to map the results?
- */
- public function remove(Integer $start, Integer $length = NULL)
- {
- throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED);
- }
- public function __construct($value = self::Blank)
- {
- try{
- try{parent::__construct($value);}
- catch(DatatypeExpectedException $e){throw new DatatypeExpectedException($e->getCode());}
- catch(ArgumentNullException $e){throw new ArgumentNullException($e->getCode());}
- }catch(SystemException $e){throw new ObjectHandlerException(ObjectHandlerException::ERROR_CAN_NOT_CREATE, $e);}
- }
- }
- interface Guid_Interface{}
- class Guid extends Object implements Guid_Interface
- {
- public function set($value)
- {
- try
- {
- $l = strlen($value);
- if(NULL === $value) throw new ArgumentNullException(ArgumentNullException::ERROR_IS_NULL);
- if(!is_string($value)) throw new DatatypeExpectedException(DatatypeExpectedException::ERROR_NOT_STRING);
- if(empty($value)) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_EMPTY_STRING);
- if($l < 32) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_INVALID_STRING_TO_SHORT);
- if($l > 32 && $l < 36) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_INVALID_STRING_LENGTH);
- if($l > 36) throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_INVALID_STRING_TO_LONG);
- if($l === 36 && FALSE === (bool) preg_match("#^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$#", $value))
- throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_INVALID_STRING_NO_PREGMATCH);
- if(FALSE === (bool) preg_match("#^[a-f0-9\-]+$#", $value))
- throw new ArgumentExpectedException(ArgumentExpectedException::ERROR_INVALID_STRING_ILLEGAL_CHAR);
- if($l === 36) return $this->format36(new String($value));
- return $this->format32(new String($value));
- }
- catch(ArgumentNullException $e){ return $this->format32(new String(md5($this->getHashCode()->get()))); }
- catch(SystemException $e){ throw new DatatypeExpectedException(DatatypeExpectedException::ERROR_NOT_GUID, $e); }
- }
- private function format32(String $value)
- {
- $int = new Integer; $cat = new String;
- return $this->format36($value
- ->insert($int->set(8), $cat->set('-'))
- ->insert($int->set(13), $cat)
- ->insert($int->set(18), $cat)
- ->insert($int->set(23), $cat));
- }
- private function format36(String $value)
- {
- return parent::set($value->get())->finalize()->lock();
- }
- public function __construct($value = NULL)
- {
- try
- {
- try{parent::__construct($value);}
- //catch(DatatypeExpectedException $e){throw new DatatypeExpectedException($e->getCode(), $e);}
- catch(ArgumentNullException $e){throw new ArgumentNullException($e->getCode());}
- }catch(SystemException $e){throw new ObjectHandlerException(ObjectHandlerException::ERROR_CAN_NOT_CREATE, $e);}
- }
- }
- interface Integer_Interface{}
- class Integer extends Object implements Integer_Interface
- {
- const Blank = 0;
- public function set($value)
- {
- if(NULL === $value) throw new ArgumentNullException;
- if(!is_integer($value)) throw new DatatypeExpectedException(DatatypeExpectedException::ERROR_NOT_INTEGER);
- parent::set($value);
- return $this;
- }
- public function equals(Integer $object){return parent::_equals($object);}
- public function compareTo(Integer $object){return parent::_compareTo($object);}
- public function __construct($value = self::Blank){parent::__construct($value);}
- }
- interface Boolean_Interface
- {
- public function toggle();
- }
- class Boolean extends Object implements Boolean_Interface
- {
- const Blank = FALSE;
- public function set($value)
- {
- if(is_bool($value)) return parent::set($value);
- try{ if(TRUE === $this->parse(($value instanceOf String) ? $value : new String($value))) parent::set((bool) $value); return $this; }
- catch(ArgumentNullException $e) { throw new DatatypeExpectedException(DatatypeExpectedException::ERROR_NOT_BOOLEAN, $e); }
- catch(FormatException $e) { throw new DatatypeExpectedException(DatatypeExpectedException::ERROR_NOT_BOOLEAN, $e); }
- }
- public function equals(Boolean $object) { return parent::_equals($object); }
- public function compareTo(Boolean $object) { return parent::_compareTo($object); }
- public static function parse(String $value)
- {
- if(NULL === $value) throw new ArgumentNullException;
- $v = $value->toLower()->trim()->apply()->get();
- if(FALSE === ((bool) ($v == self::$falseString || $v == self::$trueString))) throw new FormatException(FormatException::ERR_CANNOT_PARSE);
- return TRUE;
- }
- public function toggle() { $this->set(!$this->get()); return $this; }
- public function __construct($value = self::Blank) { parent::__construct($value); }
- private static $falseString = 'false';
- private static $trueString = 'true';
- }
- INTERFACE ObjectArray_Interface EXTENDS Object_Interface, COUNTABLE, ITERATOR, ARRAYACCESS{}
- abstract class ObjectArray extends SystemObject implements ObjectArray_Interface
- {
- // ARRAYACCESS
- final public function offsetSet($offset, $value) { $this->__stack[$offset] = $value; }
- final public function offsetExists($offset) { return isset($this->__stack[$offset]); }
- final public function offsetUnset($offset) { unset($this->__stack[$offset]); }
- final public function offsetGet($offset) { return isset($this->__stack[$offset]) ? $this->__stack[$offset] : null; }
- // COUNTABLE
- final public function count() { return sizeOf($this->__stack); }
- // ITERATOR
- final public function current() { return current($this->__stack); }
- final public function key() { return key($this->__stack); }
- final public function next() { next($this->__stack); $this->__index++; }
- final public function rewind() { reset($this->__stack); $this->__index = 0; }
- final public function valid() { return $this->__index < $this->count(); }
- // export
- public function toArray() { return $this->__stack; }
- // generic
- public function restore() { foreach($this as $key => $value) $value->restore(); return $this; }
- public function apply() { foreach($this as $key => $value) $value->apply(); return $this; }
- public function __construct() { parent::__construct(); }
- final protected function _compareTo(Object $object) { throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED); }
- protected $__stack = array();
- private $__index = 0;
- // setter/getter
- final protected function _push(Object $value) { $this->__stack[] = $value; return $this; }
- final protected function _update(Object $index, Object $value) { if(!array_key_exists($index->get(), $this->__stack)) throw new ObjectArrayException(ObjectArrayException::ERR_NO_INDEX); $this->__stack[$index->get()] = $value; return $this; }
- final protected function _get(Object $index) { if(!array_key_exists($index->get(), $this->__stack)) throw new ObjectArrayException(ObjectArrayException::ERR_NO_INDEX); return $this->__stack[$index->get()]; }
- public function exists(Object $object) { foreach($this as $key => $value) { $result = $value->equals($object); if($result->get() === TRUE) return $result; } }
- }
- INTERFACE StringArray_Interface EXTENDS String_Interface
- {
- public function update(Integer $index, String $value);
- public function get(Integer $index);
- }
- class StringArray extends ObjectArray implements StringArray_Interface
- {
- public function push(String $value) { return parent::_push($value); }
- public function get(Integer $index) { return parent::_get($index); }
- public function update(Integer $index, String $value) { return parent::_update($index, $value); }
- public function toUpper() { foreach($this as $key => $value) $value->toUpper(); return $this; }
- public function toLower() { foreach($this as $key => $value) $value->toLower(); return $this; }
- public function trim(String $replace = NULL) { foreach($this as $key => $value) $value->trim($replace); return $this; }
- public function trimStart(String $replace = NULL) { foreach($this as $key => $value) $value->trimStart(); return $this; }
- public function trimEnd(String $replace = NULL) { foreach($this as $key => $value) $value->trimEnd(); return $this; }
- public function join(String $string) { foreach($this as $key => $value) $value->join($string); return $this; }
- public function joinLeft(String $string, String $separator = NULL) { foreach($this as $key => $value) $value->joinLeft($string, $separator); return $this; }
- public function joinRight(String $string, String $separator = NULL) { foreach($this as $key => $value) $value->joinRight($string, $separator); return $this; }
- public function insert(Integer $start, String $string) { foreach($this as $key => $value) $value->insert($start, $string); return $this; }
- public function padLeft(Integer $chars, String $string = NULL) { foreach($this as $key => $value) $value->padLeft($chars, $string); return $this; }
- public function padRight(Integer $chars, String $string = NULL) { foreach($this as $key => $value) $value->padRight($chars, $string); return $this; }
- public function startsWith(String $string, Boolean $casesensitive = NULL) { foreach($this as $key => $value) $value->startsWith($string, $casesensitive); return $this; }
- public function endsWith(String $string, Boolean $casesensitive = NULL) { foreach($this as $key => $value) $value->endsWith($string, $casesensitive); return $this; }
- public function contains(String $string, Boolean $casesensitive = NULL) { foreach($this as $key => $value) $value->contains($string, $casesensitive); return $this; }
- public function indexOf(String $string, Boolean $casesensitive = NULL) { foreach($this as $key => $value) $value->indexOf($string, $casesensitive); return $this; }
- public function lastIndexOf(String $string, Boolean $casesensitive = NULL) { foreach($this as $key => $value) $value->lastIndexOf($string, $casesensitive); return $this; }
- public function replace(String $search, String $replace = NULL) { foreach($this as $key => $value) $value->replace($search, $replace); return $this; }
- public function remove(Integer $start, Integer $length = NULL) { foreach($this as $key => $value) $value->remove($search, $replace); return $this; }
- public function split(String $string = NULL) { throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED); }
- public function implode(String $string = NULL) { $l = array(); foreach($this as $key => $value) $l[] = $value->get(); return new String(($string === NULL || $string->isEmpty()->get() === TRUE) ? implode('', $l) : implode($string->get(), $l)); }
- public function length() { return new Integer($this->size()); }
- public function maxLength() { $l = array(); foreach($this as $key => $value) $l[] = $value->length()->get(); return new Integer(max($l)); }
- public function minLength() { $l = array(); foreach($this as $key => $value) $l[] = $value->length()->get(); return new Integer(min($l)); }
- public function totalLength(Boolean $asArray = NULL) { if($asArray === NULL || $asArray->get() === FALSE){ $c = 0; foreach($this as $key => $value) $c += $value->length()->get(); return new Integer($c); } $c = array(); foreach($this as $key => $value) $c[] = $value->length()->get(); return new IntegerArray($c); }
- public function findAllByMinLength(Integer $minLength) { $l = array(); foreach($this as $key => $value) if($value->length()->get() >= $minLength->get()) $l[] = $value; return new StringArray($l);}
- public function findAllByMaxLength(Integer $maxLength) { $l = array(); foreach($this as $key => $value) if($value->length()->get() <= $maxLength->get()) $l[] = $value; return new StringArray($l);}
- public function compareTo(String $string, Boolean $casesensitive = NULL) { throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED); }
- public function __construct(array $array)
- {
- parent::__construct();
- foreach($array as $string)
- try{$this->push(($string instanceOf String) ? $string : new String($string));}
- catch(ArgumentException $e){throw new ObjectArrayException(ObjectArrayException::ERR_NO_REGISTER, $e);}
- }
- }
- INTERFACE IntegerArray_Interface EXTENDS ObjectArray_Interface, Integer_Interface
- {
- public function push(Integer $value);
- }
- class IntegerArray extends ObjectArray implements IntegerArray_Interface
- {
- public function push(Integer $value){parent::_push($value);}
- public function summary()
- {
- $summary = 0;
- foreach($this as $key => $value) $summary += $value->get();
- return new Integer($summary);
- }
- public function __construct(array $array){
- foreach($array as $integer)
- try{$this->push(($integer instanceOf Integer) ? $integer : new Integer($integer));}
- catch(ArgumentException $e){throw new ObjectArrayException(ObjectArrayException::ERR_NO_REGISTER, $e);}}
- }
- header('Content-Type: text/plain');
- require_once 'units.php';
- $foo = new StringArray(array('foobar' => 'barfoo', 'foob', 'bar', 'foo'));
- var_dump($foo[0]);
- var_dump
- (
- $foo
- ->findAllByMaxLength(new Integer(3))
- ->join(new String('---'))
- ->joinLeft(new String("\n"))
- ->implode(new String(';'))
- ->joinLeft(new String("\n<<<EOF"))
- ->joinRight(new String(";\nEOF;"))
- ->get()
- );
- /*
- //$foo = new String('foobar'); var_dump($foo->join(new String('----'))->get()); // string(26) "f----o----o----b----a----r"
- $foo = new StringArray(array('foobar', 'foob', 'bar', 'foo'));
- var_dump
- (
- $foo
- ->findByMaxLength(new Integer(3))
- ->join(new String('---'))
- ->joinLeft(new String("\n"))
- ->implode(new String(';'))
- ->joinLeft(new String("\n<<<EOF"))
- ->joinRight(new String(";\nEOF;"))
- ->get()
- );
- //var_dump($foo->join(new String('----'))->get()); // string(26) "f----o----o----b----a----r"
- die();
- */
- //StringErrorUnit::ConstructNoString();
- //StringErrorUnit::SetNoString();
- //StringErrorUnit::joinLeftEmpty();
- //StringErrorUnit::joinRightEmpty();
- //StringErrorUnit::InsertEmpty();
- //StringErrorUnit::InsertIndex();
- //StringErrorUnit::PadLeftCharLength();
- //StringErrorUnit::PadRightCharLength();
- //StringErrorUnit::ContainsEmpty();
- //StringErrorUnit::StartsWithEmpty();
- //StringErrorUnit::EndsWithEmpty();
- //StringErrorUnit::IndexofEmpty();
- //StringErrorUnit::LastIndexOfEmpty();
- //StringErrorUnit::ReplaceEmpty();
- //StringErrorUnit::TrimEmpty();
- //StringUnit::String();
- //StringUnit::trimStart();
- /*
- try
- {
- //for ($j=0, $max = 10000, $s = ''; $j<$max; $j++)
- $guid = new Guid('1231212311231233211233212312345');
- var_dump($guid);
- }
- catch(SystemException $e)
- {
- print $e;
- }
- */
- //print $foo->replace(new String('te'))->toString();
- //print $foo->split()->toString();
- /*
- for($i = 0; $i <= 100; $i++)
- {
- Unit::boolean();
- Unit::string();
- Unit::integer();
- Unit::integerArray();
- Unit::stringArray();
- Unit::booleanParse();
- unit::stringTest();
- }
- */
- /*
- $foo = new String('test');
- var_dump($foo);
- */
- /*
- for ($j=0, $max = 10000; $j<$max; $j++)
- {
- $foo = new String('test');
- $foo->toUpper()->PadLeft(new Integer($foo->length()->get() + 17))->joinRight(new String(':'))->insert(new Integer(5), new String('@'));
- //unset($foo);
- }
- /*
- var_dump($foo->getType());
- foreach($foo as $bar) var_dump($bar->get());
- var_dump($foo);
- */
- //die('die:'.__FILE__.', Line:'.(__LINE__ + 46356));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement