49c31f6310062ab327e91fb15ad35133a28e591f
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
26 // Stream handler to read from global variables
33 function stream_open($path, $mode, $options, &$opened_path)
35 $url = parse_url($path);
36 $this->varname
= $url['host'];
38 if (!isset($GLOBALS[$this->varname
]))
40 trigger_error('Global variable '.$this->varname
.' does not exist', E_USER_WARNING
);
49 function stream_close()
56 function stream_read($count)
58 $ret = substr($GLOBALS[$this->varname
], $this->position
, $count);
59 $this->position +
= strlen($ret);
66 function stream_write($data)
69 if ($len > $this->position +
strlen($GLOBALS[$this->varname
])) {
70 str_pad($GLOBALS[$this->varname
], $len);
73 $GLOBALS[$this->varname
] = substr_replace($GLOBALS[$this->varname
], $data, $this->position
, $len);
74 $this->position +
= $len;
82 return $this->position
>= strlen($GLOBALS[$this->varname
]);
88 function stream_tell()
90 return $this->position
;
96 function stream_seek($offs, $whence)
108 $final = strlen($GLOBALS[$this->varname
]) +
$offs;
115 $this->position
= $final;
122 function stream_flush()
129 stream_wrapper_register('var','VarStream');