graham-campbell / github
GitHub是Laravel的GitHub桥接器
Requires
- php: ^7.4.15 || ^8.0.2
- graham-campbell/bounded-cache: ^1.2 || ^2.2
- graham-campbell/manager: ^5.1
- guzzlehttp/guzzle: ^7.8.1
- guzzlehttp/psr7: ^2.6.2
- illuminate/contracts: ^8.75 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.75 || ^9.0 || ^10.0 || ^11.0
- knplabs/github-api: 3.14.*
- lcobucci/jwt: ^4.3 || ^5.2
- symfony/cache: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- graham-campbell/analyzer: ^4.1
- graham-campbell/testbench: ^6.1
- mockery/mockery: ^1.6.6
- phpunit/phpunit: ^9.6.17 || ^10.5.13
- 12.6.x-dev
- v12.6.0
- 12.5.x-dev
- v12.5.0
- 12.4.x-dev
- v12.4.0
- 12.3.x-dev
- v12.3.0
- 12.2.x-dev
- v12.2.0
- 12.1.x-dev
- v12.1.0
- 12.0.x-dev
- v12.0.0
- 11.0.x-dev
- v11.0.0
- 10.6.x-dev
- v10.6.0
- 10.5.x-dev
- v10.5.0
- 10.4.x-dev
- v10.4.0
- 10.3.x-dev
- v10.3.1
- v10.3.0
- 10.2.x-dev
- v10.2.0
- 10.1.x-dev
- v10.1.0
- 10.0.x-dev
- v10.0.2
- v10.0.1
- v10.0.0
- 9.8.x-dev
- v9.8.2
- v9.8.1
- v9.8.0
- 9.7.x-dev
- v9.7.1
- v9.7.0
- 9.6.x-dev
- v9.6.0
- 9.5.x-dev
- v9.5.0
- 9.4.x-dev
- v9.4.0
- v9.3.1
- v9.3.0
- v9.2.1
- v9.2.0
- v9.1.1
- v9.1.0
- v9.0.1
- v9.0.0
- 8.9.x-dev
- v8.9.1
- v8.9.0
- v8.8.1
- v8.8.0
- v8.7.1
- v8.7.0
- v8.6.0
- v8.5.0
- v8.4.0
- v8.3.1
- v8.3.0
- v8.2.0
- v8.1.0
- v8.0.0
- 7.8.x-dev
- v7.8.0
- v7.7.0
- v7.6.0
- v7.5.0
- v7.4.0
- v7.3.0
- v7.2.0
- v7.1.0
- v7.0.0
- 6.2.x-dev
- v6.2.1
- v6.2.0
- v6.1.0
- v6.0.0
- 5.1.x-dev
- v5.1.0
- v5.0.0
- 4.4.x-dev
- v4.4.2
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.1
- v4.2.0
- v4.1.0
- v4.0.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.0.0
- v1.0.1
- v1.0.0
- v0.1.1-alpha
- v0.1.0-alpha
This package is auto-updated.
Last update: 2024-09-19 19:22:47 UTC
README
Laravel GitHub由Graham Campbell创建,并由他维护,是PHP GitHub API桥接器,用于Laravel。它使用了我的Laravel Manager包。您可以自由地查看变更日志、版本发布、安全策略、许可协议、行为准则和贡献指南。
安装
此版本需要PHP 7.4-8.3,并支持Laravel 8-11。
要获取最新版本,只需使用Composer引用项目。
$ composer require "graham-campbell/github:^12.6"
安装完成后,如果您未使用自动包发现,则需要将GrahamCampbell\GitHub\GitHubServiceProvider服务提供者在您的config/app.php中注册。
您还可以选择性地为我们的外观别名
'GitHub' => GrahamCampbell\GitHub\Facades\GitHub::class,
配置
Laravel GitHub需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将在您的应用中创建一个config/github.php文件,您可以修改该文件以设置配置。同时,确保检查此包的原始配置文件在版本之间的更改。
有两个配置选项
默认连接名称
此选项('default')是您指定要使用以下哪个连接作为您所有工作的默认连接的地方。当然,您可以使用管理类同时使用许多连接。此设置的默认值是'main'。
GitHub连接
此选项('connections')是设置您应用中每个连接的地方。已包含示例配置,但您可以添加尽可能多的连接。请注意,支持5种认证方法:"application"、"jwt"、"none"、"private"和"token"。
HTTP缓存
此选项('cache')是设置您应用中每个缓存配置的地方。默认提供“illuminate”驱动程序。已包含示例配置。
用法
GitHubManager
这是最具兴趣的类。它绑定到 ioc 容器中的 'github',并且可以使用 Facades\GitHub 门面进行访问。该类通过扩展 AbstractManager 实现了 ManagerInterface。该接口和抽象类都是我的 Laravel Manager 包的一部分,因此您可能想访问该存储库中的文档以了解如何使用管理器类。请注意,返回的连接类将始终是 Github\Client 的实例。
Facades\GitHub
此门面将动态地将静态方法调用传递到 ioc 容器中的 'github' 对象,默认情况下是 GitHubManager 类。
GitHubServiceProvider
该类不包含任何有趣的公共方法。应将此类添加到 config/app.php 中的 providers 数组。此类将设置 ioc 绑定。
真实示例
在这里,您可以看到使用此包是多么简单。默认情况下,默认适配器是 main。在配置文件中输入您的认证详情后,它将直接工作
use GrahamCampbell\GitHub\Facades\GitHub; // you can alias this in config/app.php if you like GitHub::me()->organizations(); // we're done here - how easy was that, it just works! GitHub::repo()->show('GrahamCampbell', 'Laravel-GitHub'); // this example is simple, and there are far more methods available
GitHub 管理器将表现得像 Github\Client 类。如果您想调用特定的连接,可以使用 connection 方法。
use GrahamCampbell\GitHub\Facades\GitHub; // the alternative connection is the other example provided in the default config GitHub::connection('alternative')->me()->emails()->add('foo@bar.com'); // now we can see the new email address in the list of all the user's emails GitHub::connection('alternative')->me()->emails()->all();
考虑到这一点,请注意
use GrahamCampbell\GitHub\Facades\GitHub; // writing this: GitHub::connection('main')->issues()->show('GrahamCampbell', 'Laravel-GitHub', 2); // is identical to writing this: GitHub::issues()->show('GrahamCampbell', 'Laravel-GitHub', 2); // and is also identical to writing this: GitHub::connection()->issues()->show('GrahamCampbell', 'Laravel-GitHub', 2); // this is because the main connection is configured to be the default GitHub::getDefaultConnection(); // this will return main // we can change the default connection GitHub::setDefaultConnection('alternative'); // the default is now alternative
如果您像我一样更喜欢使用依赖注入而不是门面,则可以轻松地将管理器注入如下
use GrahamCampbell\GitHub\GitHubManager; class Foo { private GitHubManager $github; public function __construct(GitHubManager $github) { $this->github = $github; } public function bar() { $this->github->issues()->show('GrahamCampbell', 'Laravel-GitHub', 2); } } app(Foo::class)->bar();
有关如何使用幕后调用 Github\Client 类的更多信息,请参阅此处的文档,以及管理器类此处。
更多信息
此包中还有其他未在此处记录的类。这是因为它们不是供公共使用的,而是由该包内部使用的。
安全性
如果您在此包中发现安全漏洞,请向 security@tidelift.com 发送电子邮件。所有安全漏洞都将得到及时解决。您可以在此处查看我们的完整安全策略。
许可
Laravel GitHub 在 MIT 许可证 (MIT) 下授权。
企业版
作为 Tidelift 订阅的一部分提供
graham-campbell/github 的维护者以及成千上万的其他包维护者正在与 Tidelift 合作,为您使用的开源依赖项提供商业支持和维护。节省时间,降低风险,并提高代码质量,同时支付您使用的确切依赖项的维护者。了解更多信息。
