panda843/github-api

GitHub API v3 客户端

资助包维护!
acrobat

3.8.1 2022-09-07 10:38 UTC

README

Build Status StyleCI Latest Stable Version Total Downloads Monthly Downloads Daily Downloads

一个简单的面向对象的 GitHub API 包装器,使用 PHP 编写。

使用 GitHub API v3 并支持 GitHub API v4。对象 API(v3)与 RESTful API 非常相似。

功能

  • 由于 API 类的延迟加载,轻量且快速
  • 广泛测试和文档化

要求

快速安装

通过 Composer

此命令将快速使用 Guzzle HTTP 客户端启动。

composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0

高级安装

我们通过 HTTPlug 的帮助与任何 HTTP 消息客户端解耦。

使用不同的 http 客户端

composer require knplabs/github-api:^3.0 symfony/http-client nyholm/psr7

要使用此 HTTP 客户端设置 Github 客户端

use Github\Client;
use Symfony\Component\HttpClient\HttplugClient;

$client = Client::createWithHttpClient(new HttplugClient());

在我们的文档中了解更多关于 使用不同客户端 的信息。

框架集成

Laravel

为了在 Laravel 中集成此库,Graham Campbell 创建了 graham-campbell/github。查看 安装说明 以在 Laravel 中开始。

php-github-api 客户端的基本使用

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Github\Client();
$repositories = $client->api('user')->repositories('ornicar');

$client 对象中,您可以访问所有可用的 GitHub API 端点。

缓存使用

此示例使用 PSR6 缓存池 redis-adapter。有关替代方案,请参阅 http://www.php-cache.com/

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

use Cache\Adapter\Redis\RedisCachePool;

$client = new \Redis();
$client->connect('127.0.0.1', 6379);
// Create a PSR6 cache pool
$pool = new RedisCachePool($client);

$client = new \Github\Client();
$client->addCache($pool);

// Do some request

// Stop using cache
$client->removeCache();

使用缓存,如果资源自上次以来未更改,则客户端将获取缓存的响应,无需 达到由 GitHub 强制执行的 X-Rate-Limit

文档

有关更详细的文档,请参阅 doc 目录

许可证

php-github-api 在 MIT 许可证下授权 - 有关详细信息,请参阅 LICENSE 文件

维护者

请先阅读 此帖子

此库由以下人员维护(按字母顺序排序)

贡献者

感谢 GitHub 提供高质量的 API 和文档。