-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdirectory.php
48 lines (34 loc) · 1.28 KB
/
directory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use Clue\React\ViewVcApi\Client;
use React\EventLoop\Factory as LoopFactory;
use Clue\React\Buzz\Browser;
use React\Stream\Stream;
require __DIR__ . '/../vendor/autoload.php';
$url = 'https://svn.apache.org/viewvc/';
$path = isset($argv[1]) ? $argv[1] : '/';
$revision = isset($argv[2]) ? $argv[2] : null;
$loop = LoopFactory::create();
// $dns = '10.52.166.2';
// $resolver = new React\Dns\Resolver\Factory();
// $resolver = $resolver->createCached($dns, $loop);
// $connector = new React\SocketClient\Connector($loop, $resolver);
// $socks = new \Clue\React\Socks\Client($loop, '127.0.0.1', 9050);
// $socks->setResolveLocal(false);
// $connector = $socks->createConnector();
// $sender = Clue\React\Buzz\Io\Sender::createFromLoopConnectors($loop, $connector);
$sender = null;
$browser = new Browser($loop, $sender);
$client = new Client($browser->withBase($url));
if (substr($path, -1) === '/') {
$client->fetchDirectory($path, $revision)->then('print_r', 'printf');
} else {
//$client->fetchFile($path, $revision)->then('print_r', 'printf');
$stream = $client->fetchFileStream($path, $revision);
// any errors
$stream->on('error', 'printf');
// pipe stream into STDOUT
$out = new Stream(STDOUT, $loop);
$out->pause();
$stream->pipe($out);
}
$loop->run();