clue/viewvc-api-react
Composer 安装命令:
composer require clue/viewvc-api-react
包简介
Simple, async access to ViewVC web interface (Subversion/CVS browser)
README 文档
README
Simple, async API-like access to your ViewVC web interface (Subversion/CVS browser), built on top of React PHP.
Table of Contents
Quickstart example
Once installed, you can use the following code to fetch a directory listing from the given ViewVC URL:
$loop = React\EventLoop\Factory::create(); $browser = new Clue\React\Buzz\Browser($loop); $client = new Client($browser->withBase('http://example.com/viewvc/')); $client->fetchDirectory('/')->then(function ($files) { echo 'Files: ' . implode(', ', $files) . PHP_EOL; }); $loop->run();
See also the examples.
Usage
Client
The Client is responsible for assembling and sending HTTP requests to the remote ViewVC web interface.
It requires a Browser object
bound to the main EventLoop
in order to handle async requests:
$loop = React\EventLoop\Factory::create(); $browser = new Clue\React\Buzz\Browser($loop); $client = new Client($browser->withBase('http://example.com/viewvc/'));
The Client API uses relative URIs to reference files and directories in your
ViewVC installation, so make sure to apply the base URI as depicted above.
If you need custom DNS or proxy settings, you can explicitly pass a
custom Browser instance.
Actions
ViewVC does not officially expose an API. However, its REST-like URLs make it easy to construct the right requests and scrape the results from its HTML output. All public methods resemble these respective actions otherwise available in the ViewVC web interface.
$client->fetchDirectory($path, $revision = null); $client->fetchFile($path, $revision = null); $client->fetchPatch($path, $r1, $r2); $client->fetchLog($path, $revision = null); // many more…
All actions support async operation by returning promises.
Listing all available actions is out of scope here, please refer to the class outline.
Promises
Sending requests is async (non-blocking), so you can actually send multiple requests in parallel. ViewVC will respond to each request with a response message, the order is not guaranteed. Sending requests uses a Promise-based interface that makes it easy to react to when a request is fulfilled (i.e. either successfully resolved or rejected with an error).
$client->fetchFile($path)->then( function ($contents) { // file contents received }, function (Exception $e) { // an error occured while executing the request } });
If this looks strange to you, you can also use the more traditional blocking API.
Blocking
As stated above, this library provides you a powerful, async API by default.
If, however, you want to integrate this into your traditional, blocking environment, you should look into also using clue/block-react.
The resulting blocking code could look something like this:
use Clue\React\Block; $loop = React\EventLoop\Factory::create(); $browser = new Clue\React\Buzz\Browser($loop); $client = new Client($browser->withBase($uri /* change me */)); $promise = $client->fetchFile($path /* change me */); try { $contents = Block\await($promise, $loop); // file contents received } catch (Exception $e) { // an error occured while executing the request }
Refer to clue/block-react for more details.
Streaming
The following API endpoint resolves with the file contents as a string:
$client->fetchFile($path);
Keep in mind that this means the whole string has to be kept in memory. This is easy to get started and works reasonably well for smaller files.
For bigger files it's usually a better idea to use a streaming approach, where only small chunks have to be kept in memory. This works for (any number of) files of arbitrary sizes.
The following API endpoint complements the default Promise-based API and returns
an instance implementing ReadableStreamInterface instead:
$stream = $client->fetchFileStream($path); $stream->on('data', function ($chunk) { echo $chunk; }); $stream->on('error', function (Exception $error) { echo 'Error: ' . $error->getMessage() . PHP_EOL; }); $stream->on('close', function () { echo '[DONE]' . PHP_EOL; });
Install
The recommended way to install this library is through Composer. New to Composer?
This will install the latest supported version:
$ composer require clue/viewvc-api-react:^0.4
See also the CHANGELOG for details about version upgrades.
License
MIT
clue/viewvc-api-react 适用场景与选型建议
clue/viewvc-api-react 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「async」 「subversion」 「cvs」 「reactphp」 「ViewVC」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 clue/viewvc-api-react 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 clue/viewvc-api-react 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 clue/viewvc-api-react 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP interface for version control systems
Adds output of SVN and Git 'status' commands to the Web Debug Toolbar
The bundle for easy using json-rpc api on your project
Build-Tool to automatic increase the version and create a tag in the remote VCS repository.
An async event for hyperf.
Provide cli tools to manipulate TYPO3 data.
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-07