kobermeit / github
GitHub 是 Laravel 5 的 GitHub 桥接器
Requires
- php: >=5.5.9
- graham-campbell/manager: ^2.3
- illuminate/contracts: 5.1.*|5.2.*|5.3.*|5.4.*
- illuminate/support: 5.1.*|5.2.*|5.3.*|5.4.*
- knplabs/github-api: ^2.0
Requires (Dev)
- graham-campbell/testbench: ^3.1
- madewithlove/illuminate-psr-cache-bridge: ^1.0
- mockery/mockery: ^0.9.4
- php-http/guzzle6-adapter: ^1.0
- phpunit/phpunit: ^4.8|^5.0
Suggests
- madewithlove/illuminate-psr-cache-bridge: Allows caching GitHub HTTP requests
This package is not auto-updated.
Last update: 2024-09-18 20:16:15 UTC
README
Laravel GitHub 由 Graham Campbell 创建并维护,是一个用于 Laravel 5 的 PHP GitHub API 桥接器。它使用我的 Laravel Manager 包。您可以查看 变更日志、发布、许可证 和 贡献指南。
安装
需要 PHP 5.5+ 或 HHVM 3.6+。
要获取 Laravel GitHub 的最新版本,只需使用 Composer 引入项目。
$ composer require graham-campbell/github php-http/guzzle6-adapter
例如,我使用了 php-http/guzzle6-adapter
,但您也可以安装任何“提供” php-http/client-implementation
的包。
当然,您也可以手动更新 require 块并运行 composer update
。
{ "require": { "graham-campbell/github": "^5.0", "php-http/guzzle6-adapter": "^1.1" } }
如果您想使用缓存,则需要安装 madewithlove/illuminate-psr-cache-bridge
。
一旦安装了 Laravel GitHub,您需要注册服务提供者。打开 config/app.php
并将以下内容添加到 providers
键中。
'GrahamCampbell\GitHub\GitHubServiceProvider'
您可以在 config/app.php
文件的 aliases
键中注册 GitHub facade。
'GitHub' => 'GrahamCampbell\GitHub\Facades\GitHub'
配置
Laravel GitHub 需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将在您的应用程序中创建一个 config/github.php
文件,您可以修改它来设置配置。同时,请确保检查该包中原始配置文件在发布之间的更改。
有两个配置选项
默认连接名称
此选项('default'
)指定以下连接中您希望用作所有工作的默认连接。当然,您可以使用管理器类同时使用多个连接。此设置的默认值为 'main'
。
GitHub 连接
此选项('connections'
)设置应用程序中的每个连接。已包含示例配置,但您可以添加任意数量的连接。注意,支持的 3 种身份验证方法是:"application"
、"password"
和 "token"
。
使用方法
GitHubManager
这是最感兴趣的类。它绑定到 ioc 容器中的 'github'
,可以使用 Facades\GitHub
facade 访问。此类通过扩展 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/master/doc,以及管理器类https://github.com/GrahamCampbell/Laravel-Manager#usage。
更多信息
这个包中还有其他一些没有在这里文档化的类。这是因为它们不是供公共使用的,而是由这个包内部使用的。
安全
如果您在这个包中发现安全漏洞,请将电子邮件发送到Graham Campbell的邮箱graham@alt-three.com。所有安全漏洞都将得到及时处理。
许可证
Laravel GitHub遵循MIT许可证(MIT)。