77 $this->offset = strlen( $this->contents ) +
$offset;
81 throw new \InvalidArgumentException(
"Invalid value for \$whence" );
83 if ( $this->offset > strlen( $this->contents ) ) {
84 throw new \InvalidArgumentException(
"Cannot seek beyond the end of a StringStream" );
86 if ( $this->offset < 0 ) {
87 throw new \InvalidArgumentException(
"Cannot seek before the start of a StringStream" );
99 public function write( $string ) {
100 if ( $this->offset === strlen( $this->contents ) ) {
101 $this->contents .= $string;
103 $this->contents = substr_replace( $this->contents, $string,
104 $this->offset, strlen( $string ) );
106 $this->offset += strlen( $string );
107 return strlen( $string );
114 public function read( $length ) {
115 if ( $this->offset === 0 && $length >= strlen( $this->contents ) ) {
117 } elseif ( $this->offset >= strlen( $this->contents ) ) {
120 $ret = substr( $this->contents, $this->offset, $length );
122 $this->offset += strlen( $ret );