Skip to content

Instantly share code, notes, and snippets.

@woodworker
Created March 7, 2014 14:03
Show Gist options
  • Save woodworker/0b5f823e45edbffca5b3 to your computer and use it in GitHub Desktop.
Save woodworker/0b5f823e45edbffca5b3 to your computer and use it in GitHub Desktop.
<?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');
}
<?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