用于Laravel的GitLab桥接器

4.2.0 2018-09-10 14:03 UTC

README

laravel-gitlab

这是一个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);

Build Status StyleCI Coverage Status Latest Version License

安装

Laravel GitLab与任何发送HTTP请求的库(如Guzzle)解耦,而是使用名为HTTPlug的抽象,它提供了用于向汇率服务发送请求的http层。这使您可以选择希望使用的HTTP客户端和PSR-7实现。

有关此抽象的优点以及您可能使用的不同HTTP客户端的更多信息,请参阅HTTPlug文档。以下是一个使用Guzzle 6的示例

$ composer require vinkla/gitlab php-http/guzzle6-adapter

将服务提供者添加到config/app.php文件中的providers数组中,或者如果您正在使用Laravel 5.5,则可以通过自动包发现来完成此操作。

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封装,具体可参考官方GitLab包

许可证

MIT © Vincent Klaiber