PHP code example of bitbucket / client

1. Go to this page and download the library: Download bitbucket/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/ */

    

bitbucket / client example snippets


$client = new Bitbucket\Client();

$client->authenticate(
    Bitbucket\Client::AUTH_OAUTH_TOKEN,
    'your-token-here'
);

$client = new Bitbucket\Client();

$client->authenticate(
    Bitbucket\Client::AUTH_HTTP_PASSWORD,
    '[email protected]',
    'your-api-token-here'
);

$client = new Bitbucket\Client();

$client->authenticate(
    Bitbucket\Client::AUTH_JWT,
    'your-jwt-here'
);

$currentUser = $client->currentUser()->show();

$repository = $client->repositories()
    ->workspaces('atlassian')
    ->show('stash-example-plugin');

$paginator = new Bitbucket\ResultPager($client);

$branchesClient = $client->repositories()
    ->workspaces('atlassianlabs')
    ->refs('stash-log-parser')
    ->branches();

$branches = $paginator->fetchAll($branchesClient, 'list');

$paginator = new Bitbucket\ResultPager($client);

$tagsClient = $client->repositories()
    ->workspaces('my-workspace')
    ->refs('my-repo')
    ->tags();

$tags = $paginator->fetchAll($tagsClient, 'list', [['q' => 'name ~ "v1"', 'sort' => '-name']]);

$paginator = new Bitbucket\ResultPager($client);

$srcClient = $client->repositories()
    ->workspaces('my-workspace')
    ->src('my-repo');

$entries = $paginator->fetchAll($srcClient, 'show', ['main', '/', ['max_depth' => 10]]);

$paginator = new Bitbucket\ResultPager($client);

foreach ($paginator->fetchAll($client->currentUser()->workspaces(), 'list') as $workspaceAccess) {
    $workspace = $workspaceAccess['workspace']['slug'];

    $permissions = $paginator->fetchAll(
        $client->currentUser()->workspaces()->permissions($workspace)->repositories(),
        'list'
    );
}