nutoolbox/php-gitlab-client
Composer 安装命令:
composer require nutoolbox/php-gitlab-client
包简介
A modern, type-safe PHP client for the GitLab REST API built on PSR standards.
README 文档
README
A modern, strictly typed PHP client for the GitLab REST API built on PSR standards.
Why this library?
Most existing GitLab clients rely heavily on loosely structured arrays and mirror the API 1:1. This project takes a different approach:
- Typed DTOs instead of raw arrays
- Resource-based API for better developer experience
- PSR-18 compatible HTTP layer
- Explicit authentication strategies
- Focused on maintainability and testability
Key Concept: Resource-Based API
Instead of working with raw arrays or deeply nested API calls, this client introduces resource objects.
You can start with a project and continue working within its context:
$project = $client->projects()->get('nusphere/nuclub'); $branches = $project->branches()->list(); $commits = $project->commits()->list(); $file = $project->files()->getRaw('composer.json', 'main');
This allows a more natural and expressive workflow compared to traditional API clients.
Features
-
Supports multiple authentication strategies:
- Private Token
- Bearer Token
- Job Token
- Sudo (as decorator)
-
Clean separation of concerns:
- HTTP layer
- API modules
- DTOs
- Resource objects
-
Strong typing:
ProjectResource,ProjectDetails, etc.- No raw array handling required
-
Strong error handling via domain-specific exceptions
-
Designed for testing:
- Mockable HTTP client (PSR-18)
- Fixture-based testing
Installation
composer require nutoolbox/php-gitlab-client
Usage
Basic Example
use NuToolbox\Gitlab\Client; use NuToolbox\Gitlab\Auth\GitlabAuthentication; use Nyholm\Psr7\Factory\Psr17Factory; use Symfony\Component\HttpClient\Psr18Client; $client = new Client( psrHttpClient: new Psr18Client(), requestFactory: new Psr17Factory(), authentication: GitlabAuthentication::privateToken('glpat-xxxxxxxx'), baseUrl: 'https://gitlab.example.com', ); $projects = $client->projects()->list(); foreach ($projects as $project) { echo $project->details()->pathWithNamespace . PHP_EOL; }
Working with Project Resources
$project = $client->projects()->get('nusphere/nuclub'); // Access project details echo $project->details()->name; // Work with related resources $branches = $project->branches()->list(); $commits = $project->commits()->list(); // Access repository files $content = $project->files()->getRaw('composer.json', 'main');
Direct API Access (Alternative)
You can still use the flat API if preferred:
$branches = $client->branches()->list('nusphere/nuclub'); $file = $client->repositoryFiles()->getRaw('nusphere/nuclub', 'composer.json', 'main');
Authentication
GitlabAuthentication::privateToken('glpat-...'); GitlabAuthentication::bearer('token'); GitlabAuthentication::jobToken('token'); GitlabAuthentication::sudo( GitlabAuthentication::privateToken('admin-token'), 'root' );
Testing
This library is designed to be testable.
- HTTP layer is fully mockable (PSR-18)
- Supports fixture-based testing
- No real API calls required for unit tests
Example:
$mockHttpClient = new MockHttpClient($response);
Integration tests can use environment variables:
GITLAB_BASE_URL=https://gitlab.example.com GITLAB_TOKEN=glpat-xxxxxxxx
Example integration test usage:
Requirements
- PHP 8.1+
- PSR-18 compatible HTTP client
Philosophy
This library focuses on:
- strict typing over loosely structured data
- explicit behavior over magic
- resource-oriented design over endpoint mirroring
- small, composable building blocks
- long-term maintainability over quick wrappers
License
Apache License 2.0
nutoolbox/php-gitlab-client 适用场景与选型建议
nutoolbox/php-gitlab-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nutoolbox/php-gitlab-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nutoolbox/php-gitlab-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-03-29