benmag / gitlab
用于Laravel的GitLab桥接
Requires
- php: ^5.6.4 || ^7.0
- benmag/php-gitlab-api: ^7.13
- graham-campbell/manager: ^2.4
- illuminate/contracts: 5.1.* || 5.2.* || 5.3.*
- illuminate/support: 5.1.* || 5.2.* || 5.3.*
Requires (Dev)
- graham-campbell/testbench: ^3.2
- mockery/mockery: ^0.9.5
- phpunit/phpunit: ^5.4
README
Laravel GitLab是一个使用GitLab API包的GitLab桥接,用于Laravel。
// Fetch projects. $gitlab->api('projects')->all(); // Create Issues. $gitlab->api('issues')->create($id, $params); // Want to use the facade? GitLab::api('users')->show($id);
安装
使用Composer,在项目根目录下要求此包。
composer require vinkla/gitlab
将服务提供者添加到config/app.php
中的providers
数组。
Vinkla\GitLab\GitLabServiceProvider::class
如果您想使用facade,可以在config/app.php
中将引用添加到别名数组。
'GitLab' => Vinkla\GitLab\Facades\GitLab::class
配置
Laravel GitLab需要连接配置。要开始,您需要发布所有供应商资产
php artisan vendor:publish
这将创建一个可在其中修改配置的config/gitlab.php
文件。同时,请确保检查此包中原始配置文件在版本之间的更改。
默认连接名称
此选项default
是您可能指定要用于所有工作的以下连接之一作为默认连接的地方。当然,您可以使用管理器类同时使用多个连接。此设置的默认值是main
。
GitLab连接
此选项connections
是每个连接为您应用程序设置的。已包括示例配置,但您可以根据需要添加任意数量的连接。
使用
GitLabManager
这是最感兴趣的类。它绑定到ioc容器中的gitlab
,可以通过Facades\GitLab
facade访问。此类通过扩展AbstractManager实现ManagerInterface。接口和抽象类都是Graham Campbell的Laravel Manager包的一部分,因此您可能想查看该存储库中如何使用管理器类的文档。请注意,返回的连接类始终是GitLab\Client
的实例。
Facades\GitLab
此facade将动态地将静态方法调用传递到ioc容器中的gitlab
对象,默认情况下是GitLabManager
类。
GitLabServiceProvider
此类不包含感兴趣的公共方法。应将此类添加到config/app.php
中的提供者数组。此类将设置ioc绑定。
示例
在这里,您可以看到一个示例,看看这个包有多么简单易用。开箱即用,默认适配器是 main
。在配置文件中输入您的认证信息后,它将直接工作。
// You can alias this in config/app.php. use Vinkla\GitLab\Facades\GitLab; GitLab::api('projects')->all(); // We're done here - how easy was that, it just works! GitLab::api('users')->all(true); // This example is simple and there are far more methods available.
GitLab 管理器将表现得像一个 GitLab\Client
。如果您想调用特定的连接,可以通过连接方法来实现。
use Vinkla\GitLab\Facades\GitLab; // Writing this… GitLab::connection('main')->api('projects')->all(); // …is identical to writing this GitLab::api('projects')->all(); // and is also identical to writing this. GitLab::connection()->api('projects')->all(); // This is because the main connection is configured to be the default. GitLab::getDefaultConnection(); // This will return main. // We can change the default connection. GitLab::setDefaultConnection('alternative'); // The default is now alternative.
如果您像我一样更喜欢使用依赖注入而不是外观(facade),则可以注入管理器。
use Vinkla\GitLab\GitLabManager; class Foo { protected $gitlab; public function __construct(GitLabManager $gitlab) { $this->gitlab = $gitlab; } public function bar() { $this->gitlab->api('users')->all(true); } } App::make('Foo')->bar();
文档
这个包中还有一些未在此文档中记录的类。这是因为该包是 官方 GitLab 包 的 Laravel 封装。
许可证
Laravel GitLab 采用 MIT 许可证 (MIT) 许可。