GitLab 是 Laravel 的 GitLab 桥接器


README

Laravel GitLab 由 Graham Campbell 创建并维护,是一个为 Laravel 提供的 GitLab PHP API 客户端 桥接器。它使用了我的 Laravel Manager 包。您可以自由查看变更日志发布版本安全策略许可行为准则贡献指南

Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

安装

此版本需要 PHP 7.4-8.3 并支持 Laravel 8-11。

要获取最新版本,只需使用 Composer 引入项目。

$ composer require "graham-campbell/gitlab:^7.5"

安装完成后,如果您未使用自动包发现,则需要将 GrahamCampbell\GitLab\GitLabServiceProvider 服务提供者在您的 config/app.php 中注册。

您还可以选择性地对 facade 进行别名设置

        'GitLab' => GrahamCampbell\GitLab\Facades\GitLab::class,

配置

Laravel GitLab 需要连接配置。

要开始,您需要发布所有供应商资产

$ php artisan vendor:publish

这将在您的应用程序中创建一个 config/gitlab.php 文件,您可以根据需要修改此配置。同时,请确保检查本包发布版本之间的原始配置文件的变化。

有两种配置选项

默认连接名称

此选项('default')用于指定以下连接中您希望用作所有工作的默认连接。当然,您可以使用管理器类同时使用多个连接。此设置的默认值为 'main'

GitLab 连接

此选项('connections')用于为您的应用程序设置每个连接。已包含示例配置,但您可以添加任意数量的连接。请注意,支持的四种认证方法为:"none""oauth""job_token""token"

HTTP 缓存

此选项('cache')用于为您的应用程序设置每个缓存配置。默认提供 "illuminate" 驱动。已包含示例配置。

用法

GitLabManager

这是最感兴趣的类。它绑定到上的'gitlab',可以通过Facades\GitLab外观来访问。该类通过扩展AbstractManager实现了ManagerInterface。接口和抽象类都是我Laravel Manager包的一部分,因此您可能想查看该仓库中的文档以了解如何使用管理器类。请注意,返回的连接类始终是Gitlab\Client的一个实例。

Facades\GitLab

此外观将动态地将静态方法调用传递给中的'gitlab'对象,默认情况下是GitLabManager类。

GitLabServiceProvider

此类不包含任何感兴趣的公开方法。应将此类添加到config/app.php中的提供者数组中。此类将设置ioc绑定。

真实示例

在这里,您可以看到一个使用此包的示例有多么简单。开箱即用,默认适配器是main。在您在配置文件中输入认证详情后,它就会正常工作

use GrahamCampbell\GitLab\Facades\GitLab;
// you can alias this in config/app.php if you like

GitLab::groups()->all();
// we're done here - how easy was that, it just works!

gitlab管理器将表现得像是一个Gitlab\Client类。如果您想调用特定的连接,可以使用connection方法

use GrahamCampbell\GitLab\Facades\GitLab;

// writing this:
GitLab::connection('main')->groups()->all();

// is identical to writing this:
GitLab::groups()->all();

// and is also identical to writing this:
GitLab::connection()->groups()->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

如果您像我一样喜欢使用依赖注入而不是外观,则可以轻松地以以下方式注入管理器

use GrahamCampbell\GitLab\GitLabManager;

class Foo
{
    private GitLabManager $gitlab;

    public function __construct(GitLabManager $gitlab)
    {
        $this->gitlab = $gitlab;
    }

    public function bar()
    {
        $this->gitlab->groups()->all();
    }
}

app(Foo::class)->bar();

有关如何使用我们背后调用的Gitlab\Client类的更多信息,请参阅https://github.com/GitLabPHP/Client/tree/11.13.0#general-api-usagehttps://github.com/GrahamCampbell/Laravel-Manager#usage中的文档。

更多信息

此包中还有其他未在此处文档化的类。这是因为它们不是为了公开使用而设计的,而是由此包内部使用。

安全性

如果您在此包中发现安全漏洞,请向security@tidelift.com发送电子邮件。所有安全漏洞都将得到及时解决。您可以在此处查看我们的完整安全策略https://github.com/GrahamCampbell/Laravel-GitLab/security/policy

许可

Laravel GitLab在MIT许可(MIT)下授权。

企业版

作为Tidelift订阅的一部分提供

graham-campbell/gitlab的维护者以及成千上万的其他包维护者正在与Tidelift合作,为构建应用程序时使用的开源依赖项提供商业支持和维护。节省时间,降低风险,并提高代码健康度,同时支付您使用的确切依赖项的维护者。了解更多。