PHPackages                             nutoolbox/php-gitlab-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. nutoolbox/php-gitlab-client

ActiveLibrary[API Development](/categories/api)

nutoolbox/php-gitlab-client
===========================

A modern, type-safe PHP client for the GitLab REST API built on PSR standards.

00PHPCI passing

Since Apr 3Pushed 2mo agoCompare

[ Source](https://github.com/NuToolBox/php-gitlab-client)[ Packagist](https://packagist.org/packages/nutoolbox/php-gitlab-client)[ RSS](/packages/nutoolbox-php-gitlab-client/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-gitlab-client
=================

[](#php-gitlab-client)

A modern, strictly typed PHP client for the GitLab REST API built on PSR standards.

Why this library?
-----------------

[](#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
-------------------------------

[](#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
--------

[](#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
------------

[](#installation)

```
composer require nutoolbox/php-gitlab-client
```

---

Usage
-----

[](#usage)

### Basic Example

[](#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

[](#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)

[](#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

[](#authentication)

```
GitlabAuthentication::privateToken('glpat-...');
GitlabAuthentication::bearer('token');
GitlabAuthentication::jobToken('token');

GitlabAuthentication::sudo(
    GitlabAuthentication::privateToken('admin-token'),
    'root'
);
```

---

Testing
-------

[](#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
------------

[](#requirements)

- PHP 8.1+
- PSR-18 compatible HTTP client

---

Philosophy
----------

[](#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
-------

[](#license)

Apache License 2.0

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance56

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/981e7d33e845cbf63bb52f9d61b32a41421f88392f488970a9023858aa0e30d3?d=identicon)[Nusphere](/maintainers/Nusphere)

---

Top Contributors

[![nusphere](https://avatars.githubusercontent.com/u/5822825?v=4)](https://github.com/nusphere "nusphere (32 commits)")

### Embed Badge

![Health badge](/badges/nutoolbox-php-gitlab-client/health.svg)

```
[![Health](https://phpackages.com/badges/nutoolbox-php-gitlab-client/health.svg)](https://phpackages.com/packages/nutoolbox-php-gitlab-client)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
