Created
February 3, 2014 17:47
-
-
Save cythrawll/8788694 to your computer and use it in GitHub Desktop.
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
<?php | |
class StreamThingy { | |
public $fh; //this si your fopen statement | |
public $readFunc; | |
public function onRead($function) { | |
$this->readFunc = $function; | |
} | |
public function execute() { | |
$this->fh = //do fopen logic | |
$bytes = 4096; | |
while($str = call_user_func(array($this, 'readFunc'), $fh, $bytes) !== FALSE) { | |
//do something here | |
} | |
} | |
} | |
$streamObj = new StreamThingy(); | |
$streamObj->onRead(function($handle, $bytes) { return fread($fh, $bytes); }); | |
$streamObj->execute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment