00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class StringInputStream extends InputStream
00017 {
00018 private $string = null;
00019 private $length = null;
00020
00021 private $position = 0;
00022 private $mark = 0;
00023
00024 public function __construct($string)
00025 {
00026 Assert::isString($string);
00027
00028 $this->string = $string;
00029 $this->length = strlen($string);
00030 }
00031
00035 public static function create($string)
00036 {
00037 return new self($string);
00038 }
00039
00040 public function isEof()
00041 {
00042 return ($this->position >= $this->length);
00043 }
00044
00048 public function mark()
00049 {
00050 $this->mark = $this->position;
00051
00052 return $this;
00053 }
00054
00055 public function markSupported()
00056 {
00057 return true;
00058 }
00059
00063 public function reset()
00064 {
00065 $this->position = $this->mark;
00066
00067 return $this;
00068 }
00069
00073 public function close()
00074 {
00075 $this->string = null;
00076
00077 return $this;
00078 }
00079
00080 public function read($count)
00081 {
00082 if (!$this->string || $this->isEof())
00083 return null;
00084
00085 $result = substr($this->string, $this->position, $count);
00086
00087 $this->position += $count;
00088
00089 return $result;
00090 }
00091 }
00092 ?>