This is mostly useful for using (RESTful) HTTP APIs.
Any relative URI passed to any of the request methods will simply be
appended behind the given $baseUri.
By definition of this library, a given base URI MUST always absolute and
can not contain any placeholders.
public function setUp() { $url = 'http://svn.apache.org/viewvc/'; $this->loop = LoopFactory::create(); $browser = new Browser($this->loop); $this->viewvc = new Client($browser->withBase($url)); }
public function __construct(Browser $http, Factory $resultFactory = null, UriTemplate $uri = null) { $this->http = $http->withBase('https://packagist.org/'); if (null === $resultFactory) { $resultFactory = new Factory(); } if (null === $uri) { $uri = new UriTemplate(); } $this->resultFactory = $resultFactory; $this->uri = $uri; }
public function setUp() { if (!function_exists('stream_socket_enable_crypto')) { $this->markTestSkipped('TLS (HTTPS) not supported by your platform (HHVM?)'); } $url = 'https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/'; $this->loop = LoopFactory::create(); $browser = new Browser($this->loop); // check connectivity to given URL only once static $error = null; if ($error === null) { try { Block\await($browser->get($url), $this->loop); $error = false; } catch (Exception $e) { $error = $e->getMessage(); } } if ($error !== false) { $this->markTestSkipped('Unable to reach Gentoo ViewVC: ' . $error); } $this->viewvc = new Client($browser->withBase($url)); }
public function setUp() { $this->sender = $this->getMockBuilder('Clue\\React\\Buzz\\Io\\Sender')->disableOriginalConstructor()->getMock(); $browser = new Browser($this->getMock('React\\EventLoop\\LoopInterface'), $this->sender); $this->client = new Client($browser->withBase($this->uri)); }
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();