Last active
February 20, 2017 01:10
-
-
Save falahati/371d6a83d323ca82ddd6 to your computer and use it in GitHub Desktop.
A simple stream class with no storing logic behind it. Usable to get the information that are going to be written to the stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlankStream | |
{ | |
public static $methods = false; | |
public $method = false; | |
static function GeneratePath($callBack) | |
{ | |
$args = array(); | |
if (func_num_args() > 1) | |
{ | |
$args = func_get_args(); | |
array_splice($args, 0, 1); | |
} | |
$name = "Path#" . (count(self::$methods) + 1); | |
self::$methods[$name] = array('Callback' => $callBack, 'Arguments' => $args); | |
return $name; | |
} | |
function stream_open($path, $mode, $options, &$opened_path) | |
{ | |
$opened_path = $path; | |
$parsedPath = parse_url($path); | |
if (!$parsedPath || !isset($parsedPath['host']) || !isset(self::$methods[$parsedPath['host']])) | |
{ | |
return false; | |
} | |
$mehod = self::$methods[$parsedPath['host']]; | |
$callback = $mehod['Callback']; | |
$arguments = $mehod['Arguments']; | |
if (isset($parsedPath['path'])) | |
{ | |
$path = str_replace("\\", "/", trim($parsedPath['path'], "\\/ \r\t\n")); | |
if ($path) | |
{ | |
$arguments = array_merge($arguments, explode("/", $path)); | |
} | |
} | |
return true; | |
} | |
function stream_read($count) | |
{ | |
return false; | |
} | |
function stream_write($data) | |
{ | |
call_user_func_array($callback, $arguments); | |
echo strlen($data); | |
} | |
function stream_tell() | |
{ | |
return 0; | |
} | |
function stream_eof() | |
{ | |
return true; | |
} | |
function stream_seek($offset, $whence) | |
{ | |
return false; | |
} | |
function stream_metadata($path, $option, $var) | |
{ | |
if($option == STREAM_META_TOUCH) { | |
return true; | |
} | |
return false; | |
} | |
} | |
@stream_wrapper_register("blank", "BlankStream"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment