Advertisement
fruffl

Untitled

Sep 16th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.59 KB | None | 0 0
  1.             INTERFACE StringArray_Interface EXTENDS String_Interface
  2.             {
  3.                     public          function update(Integer $index, String $value);
  4.                     public          function get(Integer $index);
  5.             }
  6.             class StringArray extends ObjectArray implements StringArray_Interface
  7.             {
  8.                     public          function push(String $value)                        { return parent::_push($value);}
  9.                     public          function get(Integer $index)                        { return parent::_get($index);}
  10.                     public          function update(Integer $index, String $value)              { return parent::_update($index, $value);}
  11.                     public          function toUpper()                          { foreach($this as $key => $value) $value->toUpper(); return $this;}
  12.                     public          function toLower()                          { foreach($this as $key => $value) $value->toLower(); return $this;}
  13.                     public          function trim(String $replace = NULL)                   { foreach($this as $key => $value) $value->trim($replace); return $this;}
  14.                     public          function trimStart(String $replace = NULL)              { foreach($this as $key => $value) $value->trimStart(); return $this;}
  15.                     public          function trimEnd(String $replace = NULL)                { foreach($this as $key => $value) $value->trimEnd(); return $this;}
  16.                     public          function leftJoin(String $string, String $separator = NULL)     { foreach($this as $key => $value) $value->leftJoin($string, $separator); return $this;}
  17.                     public          function rightJoin(String $string, String $separator = NULL)        { foreach($this as $key => $value) $value->rightJoin($string, $separator); return $this;}
  18.                     public          function insert(Integer $start, String $string)             { foreach($this as $key => $value) $value->insert($start, $string); return $this;}
  19.                     public          function padLeft(Integer $chars, String $string = NULL)         { foreach($this as $key => $value) $value->padLeft($chars, $string); return $this;}
  20.                     public          function padRight(Integer $chars, String $string = NULL)        { foreach($this as $key => $value) $value->padRight($chars, $string); return $this;}
  21.                     public          function length()                           { return new Integer($this->size());}
  22.                     public          function maxLength()                            { $l = array(); foreach($this as $key => $value) $l[] = $value->length()->get(); return new Integer(max($l));} 
  23.                     public          function minLength()                            { $l = array(); foreach($this as $key => $value) $l[] = $value->length()->get(); return new Integer(min($l));}
  24.                     public          function startsWith(String $string, Boolean $casesensitive = NULL)  { foreach($this as $key => $value) $value->startsWith($string, $casesensitive); return $this;}
  25.                     public          function endsWith(String $string, Boolean $casesensitive = NULL)    { foreach($this as $key => $value) $value->endsWith($string, $casesensitive); return $this;}
  26.                     public          function contains(String $string, Boolean $casesensitive = NULL)    { foreach($this as $key => $value) $value->contains($string, $casesensitive); return $this;}
  27.                     public          function indexOf(String $string, Boolean $casesensitive = NULL)     { foreach($this as $key => $value) $value->indexOf($string, $casesensitive); return $this;}
  28.                     public          function lastIndexOf(String $string, Boolean $casesensitive = NULL) { foreach($this as $key => $value) $value->lastIndexOf($string, $casesensitive); return $this;}
  29.                     public          function replace(String $search, String $replace = NULL)        { foreach($this as $key => $value) $value->replace($search, $replace); return $this;}
  30.                     public          function remove(Integer $start, Integer $length = NULL)         { foreach($this as $key => $value) $value->remove($search, $replace); return $this;}
  31.                     public          function split(String $string = NULL)                   { throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED); }
  32.                     public          function totalLength(Boolean $asArray = NULL)
  33.                                 {
  34.                                     if($asArray === NULL || $asArray->get() === FALSE)
  35.                                     {
  36.                                         $counter = 0; foreach($this as $key => $value) $counter += $value->length()->get();
  37.                                         return new Integer($counter);
  38.                                     }
  39.                                    
  40.                                     $counter = array();
  41.                                     foreach($this as $key => $value)
  42.                                         $counter[] = $value->length()->get();
  43.                                     return new IntegerArray($counter);
  44.                                 }
  45.                     public          function compareTo(String $string, Boolean $casesensitive = NULL)   { throw new ImplementationException(ImplementationException::ERROR_METHOD_NOT_IMPLEMENTED); }
  46.                     public          function __construct(array $array)
  47.                                 {
  48.                                     parent::__construct();
  49.                                     foreach($array as $string)
  50.                                         try{$this->push(($string instanceOf String) ? $string : new String($string));}
  51.                                         catch(ArgumentException $e){throw new ObjectArrayException(ObjectArrayException::ERR_NO_REGISTER, $e);}
  52.                                 }
  53.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement