potherca/flysystem-github

Github Flysystem 适配器

v0.3.0 2016-04-20 17:04 UTC

README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

安装

通过 Composer

$ composer require potherca/flysystem-github

使用方法

Github 适配器可以在不提供凭证的情况下用于对公共仓库进行只读操作。为了避免达到 Github API 的限制,保存更改或从私有仓库读取,则需要凭证。

可以使用缓存来节省流量或推迟达到 Github API 的限制。

基本使用

use Github\Client;
use League\Flysystem\Filesystem;
use Potherca\Flysystem\Github\Api;
use Potherca\Flysystem\Github\GithubAdapter;
use Potherca\Flysystem\Github\Settings;

$project = 'thephpleague/flysystem';

$settings = new Settings($project);

$api = new Api(new Client(), $settings);
$adapter = new GithubAdapter($api);
$filesystem = new Filesystem($adapter);

身份验证

use Github\Client;
use League\Flysystem\Filesystem;
use Potherca\Flysystem\Github\Api;
use Potherca\Flysystem\Github\GithubAdapter;
use Potherca\Flysystem\Github\Settings;

$project = 'thephpleague/flysystem';
$credentials = [Settings::AUTHENTICATE_USING_TOKEN, '83347e315b8bb4790a48ed6953a5ad9e825b4e10'];
// or $authentications = [Settings::AUTHENTICATE_USING_PASSWORD, $username, $password];
    
$settings = new Settings($project, $credentials);

$api = new Api(new Client(), $settings);
$adapter = new GithubAdapter($api);
$filesystem = new Filesystem($adapter);

缓存使用

use Github\Client;
use Github\HttpClient\CachedHttpClient as CachedClient;
use Github\HttpClient\Cache\FilesystemCache as Cache;
use League\Flysystem\Filesystem;
use Potherca\Flysystem\Github\Api;
use Potherca\Flysystem\Github\GithubAdapter;
use Potherca\Flysystem\Github\Settings;

$project = 'thephpleague/flysystem';

$settings = new Settings($project);

$cache = new Cache('/tmp/github-api-cache')
$cacheClient = new CachedClient();
$cacheClient->setCache($cache);

$api = new Api($cacheClient, $settings);
$adapter = new GithubAdapter($api);
$filesystem = new Filesystem($adapter);

测试

可以使用以下命令运行单元测试:

$ composer test

要运行使用 Github API 的集成测试,可能需要一个 Github API 令牌(以避免测试达到 API 限制)。可以通过将环境变量设置为 GITHUB_API_KEY 或在集成测试目录中创建一个 .env 文件并设置它来添加 API 密钥。有关示例,请参阅 tests/integration-tests/.env.example

要运行集成测试(这也会运行单元测试),请运行以下命令:

$ composer test-all

安全

如果您发现任何与安全相关的问题,请通过电子邮件 potherca@gmail.com 联系,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

变更日志

有关详细信息,请参阅 CHANGELOG

鸣谢

许可协议

MIT 许可协议(MIT)。有关更多信息,请参阅 许可文件