PHP code example of emri99 / gitlab-generic-api-client

1. Go to this page and download the library: Download emri99/gitlab-generic-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

emri99 / gitlab-generic-api-client example snippets


$client->authenticate('SECRET-HTTP-TOKEN', GitlabApiClient::AUTH_HTTP_TOKEN);

$client->authenticate('SECRET-OAUTH-TOKEN', GitlabApiClient::AUTH_OAUTH_TOKEN);

$client = new GitlabApiClient('https://my.gitlab.com/api/v4');
$branches = $client->projects(1)
    ->repository()
    ->branches()
    ->get()
    
// will send GET request on 
// https://my.gitlab.com/api/v4/projects/1/repository/branches.

foreach($branches as $branch) {
    echo $branch->name, "\n";
}

# create a variable secret
$variableDatas = $this->getClient()
    ->projects(2)
    ->variables()
    ->post([
        'key' => 'SECRET',
        'value' => 'password'
    ]);

# protect a branch
$branchUpdated = $this->getClient()
    ->projects(2)
    ->repository()
    ->branches('master')
    ->protect()->put([
        'developers_can_push' => false,
        'developers_can_merge' => false
    ]);
$done = $branchUpdated->protected;

# delete a branch
$branchUpdated = $this->getClient()
    ->projects(2)
    ->repository()
    ->branches('obsolet-feature')
    ->delete();

$client = new GitlabApiClient('https://my.gitlab.com/api/v4');

/** 
 * $branches aint really a Branch instance 
 * @var Branch[] $branches 
 */
$branches = $client->projects(1)
    ->repository()
    ->branches()
    ->get(array(
        // parameters
    ))

// $branches is an array of stdclass having 
// the same properties than a Branch class
foreach($branches as $branch) {
    echo $branch->name;
}