zeichen32 / gitlabapibundle
Symfony 扩展包,用于包含 GitLab API。
v6.1.1
2024-01-10 18:06 UTC
Requires
- php: ^7.2||^8.0
- m4tthumphrey/php-gitlab-api: ^11.0
- nyholm/psr7: ^1.0
- symfony/framework-bundle: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/http-client: ^4.4 || ^5.0 || ^6.0 || ^7.0
- symfony/http-client-contracts: ^1.0|^2.0|^3.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- http-interop/http-factory-guzzle: ^1.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-10 19:34:50 UTC
README
此扩展包将 GitLab PHP API 客户端 集成到您的 Symfony 项目中。
步骤 1:安装 Zeichen32GitLabApiBundle
安装此扩展包的首选方式是依赖于 Composer。
{ "require": { // ... "guzzlehttp/guzzle:^7.0.1", // Optional PSR Client, if you dont want to use the symfony http client "zeichen32/gitlabapibundle": "~6.1" } }
步骤 2:启用扩展包
最后,在 kernel 中启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Zeichen32\GitLabApiBundle\Zeichen32GitLabApiBundle(), ); }
步骤 3:配置 Zeichen32GitLabApiBundle
在 app/config/config.yml 中添加 Zeichen32GitLabApiBundle 设置
zeichen32_git_lab_api: clients: firstclient: token: your-api-token url: http://example.org/api/v3/ auth_method: http_token secondclient: token: your-api-token url: http://example.org/api/v3/ auth_method: oauth_token sudo: 1 thirdclient: token: your-api-token url: http://example.org/api/v3/ alias: custom_alias
第一个客户端自动定义为默认客户端。
步骤 4:使用 gitlab api
如果您想使用默认客户端,可以使用类型提示。
<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Gitlab\Client; class DefaultController extends AbstractController { public function index(Client $client) { $issues = $client->api('issues')->all($project_id); } }
如果您想获取其他客户端之一,可以通过 "zeichen32_gitlabapi.client.CLIENT_NAME" 服务 ID 获取特定客户端。
services: App\Controller\DefaultController: arguments: {$client: '@zeichen32_gitlabapi.client.default'}
<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Gitlab\Client; class DefaultController extends AbstractController { private $client; public __construct(Client $client) { $this->client = $client; } public function index() { $issues = $this->client->api('issues')->all($project_id); } }
或者如果您设置了别名选项
services: App\Controller\DefaultController: arguments: {$client: '@custom_alias'}
有关使用 API 的更多信息,请参阅 GitLab 客户端文档。
步骤 5:配置参考
以下列出了所有可用的配置选项及其默认值
zeichen32_git_lab_api: clients: # Required token: ~ # Required url: ~ # Required auth_method: ~ http_token|oauth_token sudo: ~ alias: ~ http_client: ~ # http client service id
许可证
此扩展包受 MIT 许可证的保护。请参阅包中的完整许可证。
Resources/meta/LICENSE