74 $this->offset = strlen( $this->contents ) +
$offset;
78 throw new \InvalidArgumentException(
"Invalid value for \$whence" );
80 if ( $this->offset > strlen( $this->contents ) ) {
81 throw new \InvalidArgumentException(
"Cannot seek beyond the end of a StringStream" );
83 if ( $this->offset < 0 ) {
84 throw new \InvalidArgumentException(
"Cannot seek before the start of a StringStream" );
96 public function write( $string ) {
97 if ( $this->offset === strlen( $this->contents ) ) {
98 $this->contents .= $string;
100 $this->contents = substr_replace( $this->contents, $string,
101 $this->offset, strlen( $string ) );
103 $this->offset += strlen( $string );
104 return strlen( $string );
111 public function read( $length ) {
112 if ( $this->offset === 0 && $length >= strlen( $this->contents ) ) {
114 } elseif ( $this->offset >= strlen( $this->contents ) ) {
117 $ret = substr( $this->contents, $this->offset, $length );
119 $this->offset += strlen( $ret );