etshy / gitlabapi-bundle
简单的 Gitlab API Bundle
v1.0.3
2022-02-07 23:30 UTC
Requires
- php: >=7.4
- m4tthumphrey/php-gitlab-api: ^11.7
- nyholm/psr7: ^1.4
- symfony/framework-bundle: ^5.4 || ^6.0
- symfony/http-client: ^5.4 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.5
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/css-selector: ^5.4 || ^6.0
- symfony/phpunit-bridge: ^6.0
README
此 Bundle 将 GitLab PHP API Client 集成到您的 Symfony 项目中。
非常受 Zeichen32GitLabApiBundle 的启发。
我创建此 Bundle 以能够拥有未经身份验证的 Gitlab Api 客户端(用于访问公开端点)
1. 安装
最推荐的方式是使用 composer
composer require etshy/gitlabapi-bundle
如果您的应用使用 Symfony/flex
,安装已完成
否则,您需要执行以下操作
// config/bundles.php
// ...
return [
...
Etshy\Gitlabapibundle\EtshyGitlabApiBundle::class => ['all' => true],
...
];
2. 配置
etshy_gitlab_api:
clients:
client_1: # This is used as name to complete default alias syntax : etshy_gitlab_api.client.client_1
# All options below are optional
token: api-token # if not present, only public api will work
url: https://gitlab.com # by default to gitlab.com. could be used to access your self-hosted gitlab
auth_method: http_token # http_token or oauth_token
sudo: ~ # use the sudo param of the GitLab PHP API Client, should be a user's ID or username to impersonate
# (more details about sudo on the API doc : https://docs.gitlab.com/ee/api/#sudo)
alias: service_alias # Symfony service custom alias
http_client: http_client_service_alias # the symfony service alias for a HttpClient to use. by Default we use Symfony Psr18Client
此 Bundle 将创建一个默认客户端,它将是第一个配置的客户端或名为 'default' 的客户端
3. 使用
现在您应该可以使用类型提示使用默认客户端
use Gitlab\Client;
class MyClass
{
public function __construct(Client $client)
}
通过此 $client,您可以使用 GitLab PHP API Client 方法
$client->api('issues')->all($project_id);
或者实例化其他 GitLab PHP API Client 类,例如
$pager = new Gitlab\ResultPager($client);
如果您想实例化另一个客户端,您需要在 services.yml
中指定它
services:
MyClass:
arguments: { $client: '@etshy_gitlab_api.client.client_1' }