panda843 / github
GitHub 是 Laravel 的 GitHub 通道
Requires
- php: ^7.2.5 || ^8.0
- graham-campbell/bounded-cache: ^1.1 || ^2.0
- graham-campbell/manager: ^4.7
- illuminate/contracts: ^6.0 || ^7.0 || ^8.0 || ^9.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0 || ^9.0
- panda843/github-api: 3.8.*
- symfony/cache: ^4.3 || ^5.0 || ^6.0
Requires (Dev)
- graham-campbell/analyzer: ^3.0
- graham-campbell/testbench: ^5.7
- guzzlehttp/guzzle: ^7.4
- http-interop/http-factory-guzzle: ^1.0
- lcobucci/jwt: ^3.4 || ^4.0
- mockery/mockery: ^1.3.1
- phpunit/phpunit: ^8.5.8 || ^9.3.7
Suggests
- lcobucci/jwt: Allows using the private key authenticator (^3.4 || ^4.0)
This package is auto-updated.
Last update: 2024-09-07 15:07:45 UTC
README
Laravel GitHub 由 Graham Campbell 创建并维护,是一个 PHP GitHub API 通道,用于 Laravel。它利用了我的 Laravel Manager 包。您可以随意查看 变更日志、版本发布、安全策略、许可协议、行为准则 和 贡献指南。
安装
此版本需要 PHP 7.4-8.1,并支持 Laravel 8-9。
要获取最新版本,只需使用 Composer 引入项目
$ composer require "graham-campbell/github:^11.0"
安装后,如果您没有使用自动包发现,则需要在您的 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'
)是针对您的应用程序设置每个连接的地方。已包括示例配置,但您可以添加任意数量的连接。请注意,支持的 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; use Illuminate\Support\Facades\App; // you probably have this aliased already class Foo { protected $github; public function __construct(GitHubManager $github) { $this->github = $github; } public function bar() { $this->github->issues()->show('GrahamCampbell', 'Laravel-GitHub', 2); } } App::make('Foo')->bar();
有关如何使用我们背后调用的Github\Client
类的更多信息,请查看https://github.com/KnpLabs/php-github-api/tree/v3.3.0/doc中的文档,以及https://github.com/GrahamCampbell/Laravel-Manager#usage中的管理器类。
更多信息
这个包中还有其他一些未在这里文档化的类。这是因为它们不是用于公开使用的,而是由这个包内部使用的。
安全
如果您在这个包中发现安全漏洞,请发送电子邮件至security@tidelift.com。所有安全漏洞都将得到及时处理。您可以在这里查看我们的完整安全策略。
许可证
Laravel GitHub使用MIT许可证(MIT)授权。
针对企业
作为Tidelift订阅的一部分提供
graham-campbell/github
的维护者以及成千上万的其他包维护者正在与Tidelift合作,为构建应用程序时使用的开源依赖项提供商业支持和维护。节省时间,降低风险,提高代码质量,同时为使用的确切依赖项支付维护者的费用。了解更多。