I have written a stream wrapper that behaves just like the File System stream wrapper because it only translates URLs into something that File System can handle in calls such as (include 'custom://module/path/to/file.php', is_file, is_readable, fopen, etc). It works, but I can't help but think that there has to be a better way.
Here is a part of the code:
class MyStream {
// ...
public function stream_open ($path, $mode, $options, &$opened_path)
{
// translate the given url into an actual file path
$this->real_path = self::translate($path);
$this->resource = fopen($this->real_path, $mode);
if ($this->resource !== false && ($options & STREAM_USE_PATH) === STREAM_USE_PATH) {
$opened_path = $this->resource;
}
return $this->resource !== false;
}
public function stream_close ()
{
fclose($this->resource);
}
public function stream_read ($count)
{
return fread($this->resource, $count);
}
public function stream_write ($data)
{
return fwrite($this->resource, $data);
}
// etc for about [B]twenty[/B] methods.
Is there some sort of filter that I can use to accomplish this without all this overhead and to minimize the areas where I could screw up?