PHP code example of alrayyes / forge-dashboard-sdk-php

1. Go to this page and download the library: Download alrayyes/forge-dashboard-sdk-php 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/ */

    

alrayyes / forge-dashboard-sdk-php example snippets


use ForgeDashboard\Client;

$client = new Client(
    'https://forge-dashboard.example.com',
    apiToken: getenv('FORGE_DASHBOARD_API_TOKEN'),
);

use ForgeDashboard\Client;

$client = new Client('https://forge-dashboard.example.com');

$version = $client->health->getVersion();
echo "server version: {$version->getVersion()}\n";

use ForgeDashboard\Client;
use ForgeDashboard\Exception\ApiError;
use ForgeDashboard\Generated\ApiException;

$client = new Client(
    'https://forge-dashboard.example.com',
    apiToken: getenv('FORGE_DASHBOARD_API_TOKEN'),
);

try {
    $dashboard = $client->dashboard->getDashboard();
    foreach ($dashboard->getPullRequests() as $pr) {
        echo "{$pr->getTitle()}: {$pr->getCi()}\n";
    }
} catch (ApiException $exception) {
    $error = ApiError::fromGeneratedException($exception);
    if ($error->statusCode === 401) {
        exit('API token expired or invalid');
    }

    throw $error;
}
sh
composer