aswilam / github
GitHub Is A GitHub Bridge For Laravel
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
- illuminate/support: ^8.75 || ^9.0 || ^10.0
- knplabs/github-api: 3.13.*
- lcobucci/jwt: ^4.3 || ^5.2
- symfony/cache: ^5.4 || ^6.0
Requires (Dev)
- graham-campbell/analyzer: ^4.1
- graham-campbell/testbench: ^6.1
- mockery/mockery: ^1.6.6
- phpunit/phpunit: ^9.6.15 || ^10.4.2
This package is auto-updated.
Last update: 2024-09-17 16:30:51 UTC
README
Laravel GitHub 由 GrahamCampbell 创建并维护,是一个 PHP GitHub API 的桥接器,用于 Laravel。它利用了我的 Laravel Manager 包。您可以随意查看 变更日志、发行版、安全策略、许可证、行为准则 和 贡献指南。
安装
此版本需要 PHP 7.4-8.3 并支持 Laravel 8-10。
要获取最新版本,只需使用 Composer 需求项目
$ composer require "graham-campbell/github:^12.4"
安装后,如果您未使用自动包发现,则需要在您的 config/app.php
中注册 GrahamCampbell\GitHub\GitHubServiceProvider
服务提供者。
您还可以可选地别名我们的外观
'GitHub' => GrahamCampbell\GitHub\Facades\GitHub::class,
配置
Laravel GitHub 需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将在您的应用中创建一个 config/github.php
文件,您可以修改它来设置配置。同时,请确保检查此包中原始配置文件在发布之间的更改。
有两个配置选项
默认连接名称
此选项('default'
)是您指定要使用的以下连接之一作为所有工作的默认连接的地方。当然,您可以使用管理器类同时使用多个连接。此设置的默认值为 'main'
。
GitHub 连接
此选项('connections'
)是为您的应用程序设置每个连接的地方。已包括示例配置,但您可以添加尽可能多的连接。请注意,支持的身份验证方法有:"application"
、"jwt"
、"none"
、"private"
和 "token"
。
HTTP 缓存
此选项('cache'
)是为您的应用程序设置每个缓存配置的地方。默认情况下仅提供 "illuminate" 驱动。已包括示例配置。
使用方法
GitHubManager
这是最感兴趣的类。它绑定到 'github'
的 ioc 容器,并且可以通过使用 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
类的更多信息,请参阅 https://github.com/KnpLabs/php-github-api/tree/v3.13.0/doc 上的文档,以及管理类在 https://github.com/GrahamCampbell/Laravel-Manager#usage。
更多信息
这个包中还有其他一些未在此文档中记录的类。这是因为它们不是用于公共用途的,而是由这个包内部使用的。
安全性
如果你在这个包中发现安全漏洞,请发送电子邮件至 security@tidelift.com。所有安全漏洞都将得到及时处理。你可以在这里查看我们的完整安全策略 这里。
许可
Laravel GitHub 在 The MIT License (MIT) 许可下授权。
企业版
作为 Tidelift 订阅的一部分提供
graham-campbell/github
的维护者以及成千上万的其他包维护者正在与 Tidelift 合作,为构建应用程序时使用的开源依赖项提供商业支持和维护。节省时间,降低风险,并提高代码健康度,同时支付你确切使用的依赖项的维护者。了解更多信息 这里。