Created
March 7, 2014 14:03
-
-
Save woodworker/0b5f823e45edbffca5b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
require_once(__DIR__.'/functions.php') | |
stream_wrapper_register("proc", "ProcStream"); | |
$user = opt('u', ['svnuser']); | |
$reader = new XMLReader(); | |
$reader->open('proc://svn log -l 3 --xml'); | |
// fast forward to first logentry | |
while ($reader->read() && $reader->name !== 'logentry'); | |
while ($reader->name === 'logentry') { | |
$node = new SimpleXMLElement($reader->readOuterXML()); | |
printf("%s: %s", $node->author, $node->msg); | |
$reader->next('logentry'); | |
} |
This file contains hidden or 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 ProcStream { | |
/** | |
* @var resource | |
*/ | |
protected $process; | |
/** | |
* @var array | |
*/ | |
protected $pipes; | |
public function stream_open($path, $mode, $options, &$opened_path) { | |
$url = parse_url($path); | |
$start = strlen($url['scheme']) + 3; // 3 = strlen('://') | |
$command = substr($path, $start); | |
$descriptorSpec = array( | |
0 => array("pipe", "r"), // stdin is a pipe that the child will read from | |
1 => array("pipe", "w"), // stdout is a pipe that the child will write to | |
2 => array("pipe", "w") // stderr is a pipe that the child will write to | |
); | |
$this->process = proc_open($command, $descriptorSpec, $this->pipes, realpath('./')); | |
if (!is_resource($this->process)) { | |
return false; | |
} | |
return true; | |
} | |
public function stream_read($count) { | |
return fread($this->pipes[1], $count); | |
} | |
public function stream_write($data) { | |
return fwrite($this->pipes[0], $data); | |
} | |
public function stream_eof() { | |
$status = proc_get_status($this->process); | |
return !$status['running']; | |
} | |
public function stream_close() { | |
return proc_close($this->process); | |
} | |
public function url_stat($path, $flags) { | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment