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