We present a modern GitLab API v4 client for PHP.
This is strongly based on php-github-api by KnpLabs. With this in mind, we now have very similar clients for:
- Bitbucket - bitbucket/client by Graham Campbell.
- GitHub - knplabs/github-api by KnpLabs.
- GitLab - m4tthumphrey/php-gitlab-api which is this package!
Check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.
This version supports PHP 5.6-7.4. To get started, simply require the project using Composer. You will also need to install any package that "provides" php-http/client-implementation
.
$ composer require m4tthumphrey/php-gitlab-api:^9.18 php-http/guzzle6-adapter:^2.0.1
$ composer require graham-campbell/gitlab:^2.7 php-http/guzzle6-adapter:^2.0.1
$ composer require graham-campbell/gitlab:^3.2 php-http/guzzle6-adapter:^2.0.1
$ composer require zeichen32/gitlabapibundle:^3.1 php-http/guzzle6-adapter:^2.0.1
$ composer require zeichen32/gitlabapibundle:^4.0 php-http/guzzle6-adapter:^2.0.1
We are decoupled from any HTTP messaging client by using PSR-7 and HTTPlug. You can visit HTTPlug for library users to get more information about installing HTTPlug related packages. The framework integration graham-campbell/gitlab is by Graham Campbell and zeichen32/gitlabapibundle is by Jens Averkamp.
// Token authentication
$client = new Gitlab\Client();
$client->authenticate('your_http_token', Gitlab\Client::AUTH_HTTP_TOKEN);
// OAuth2 authentication
$client = new Gitlab\Client();
$client->authenticate('your_oauth_token', Gitlab\Client::AUTH_OAUTH_TOKEN);
// An example API call
$project = $client->projects()->create('My Project', [
'description' => 'This is a project',
'issues_enabled' => false,
]);
$client = new Gitlab\Client();
$client->setUrl('https://git.yourdomain.com');
$client->authenticate('your_http_token', Gitlab\Client::AUTH_HTTP_TOKEN);
$pager = new Gitlab\ResultPager($client);
$issues = $pager->fetchAll($client->issues(), 'all', [null, ['state' => 'closed']]);
You can also use the library in an object oriented manner:
// Creating a new project
$project = Gitlab\Model\Project::create($client, 'My Project', [
'description' => 'This is my project',
'issues_enabled' => false,
]);
$project->addHook('https://mydomain.com/hook/push/1');
// Creating a new issue
$project = new Gitlab\Model\Project(1, $client);
$issue = $project->createIssue('This does not work.', [
'description' => 'This doesn\'t work properly. Please fix.',
'assignee_id' => 2,
]);
// Closing that issue
$issue->close();
By providing a Gitlab\HttpClient\Builder
to the Gitlab\Client
constructor, you can customize the HTTP client. For example, to customize the user agent:
$plugin = new Http\Client\Common\Plugin\HeaderSetPlugin([
'User-Agent' => 'Foobar',
]);
$builder = new Gitlab\HttpClient\Builder();
$builder->addPlugin($plugin);
$client = new Gitlab\Client($builder);
One can read more about HTTPlug plugins here. Take a look around (API methods, models) and please feel free to report any bugs, noting our code of conduct.
We will gladly receive issue reports and review and accept pull requests, in accordance with our code of conduct and contribution guidelines!
$ make install
$ make test
If you discover a security vulnerability within this package, please send an email to Graham Campbell at [email protected] or Miguel Piedrafita at [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here.
GitLab PHP API Client is licensed under The MIT License (MIT).