varname = $url['host']; $this->position = 0; if (!isset($GLOBALS[$this->varname])) { trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING); return false; } return true; } public function stream_close() { } public function stream_read($count) { $ret = substr($GLOBALS[$this->varname], $this->position, $count); $this->position += strlen($ret); return $ret; } public function stream_write($data) { $len = strlen($data); if ($len > $this->position + strlen($GLOBALS[$this->varname])) { str_pad($GLOBALS[$this->varname], $len); } $GLOBALS[$this->varname] = substr_replace($GLOBALS[$this->varname], $data, $this->position, $len); $this->position += $len; } public function stream_eof() { return $this->position >= strlen($GLOBALS[$this->varname]); } public function stream_tell() { return $this->position; } public function stream_seek($offs, $whence) { switch ($whence) { case SEEK_SET: $final = $offs; break; case SEEK_CUR: $final += $offs; break; case SEEK_END: $final = strlen($GLOBALS[$this->varname]) + $offs; break; } if ($final < 0) { return -1; } $this->position = $final; return 0; } public function stream_flush() { } static public function init() { stream_wrapper_register('var','VarStream'); } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>