PHP code example of conduit-ui / connector

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

    

conduit-ui / connector example snippets


use ConduitUi\GitHubConnector\Connector;

$connector = new Connector('ghp_your_token_here');

// Make requests - exceptions are typed automatically
try {
    $repos = $connector->send($getUserReposRequest);
    $newRepo = $connector->send($createRepoRequest);
} catch (GitHubRateLimitException $e) {
    // Handle rate limits with context
} catch (GitHubAuthException $e) {
    // Handle auth failures
}

$connector = new Connector('ghp_your_token_here');

use Saloon\Http\Request;
use Saloon\Enums\Method;

class GetUserRepos extends Request
{
    protected Method $method = Method::GET;

    public function resolveEndpoint(): string
    {
        return '/user/repos';
    }
}

$response = $connector->send(new GetUserRepos());
$repos = $response->json();

use ConduitUi\GitHubConnector\Exceptions\{
    GitHubAuthException,           // 401 Unauthorized
    GitHubForbiddenException,      // 403 Forbidden
    GitHubResourceNotFoundException, // 404 Not Found
    GitHubValidationException,     // 422 Validation Failed
    GitHubRateLimitException,      // 429 Rate Limited
    GitHubServerException          // 500+ Server Errors
};

try {
    $response = $connector->send($request);
} catch (GitHubRateLimitException $e) {
    // Check rate limit headers
    $resetAt = $e->getResponse()->header('X-RateLimit-Reset');
    sleep($resetAt - time());
    // Retry...
} catch (GitHubResourceNotFoundException $e) {
    // Handle missing resource
} catch (GitHubException $e) {
    // Catch-all for any GitHub API error
}

$response = $connector->send($request);

$remaining = $response->header('X-RateLimit-Remaining');
$resetAt = $response->header('X-RateLimit-Reset');

use ConduitUi\GitHubConnector\Connector;

// Set the repo context once
Connector::forRepo('owner/repo');

// All ecosystem packages now inherit this context
Issue::all();           // No repo arg needed
PullRequests::open();   // No repo arg needed
Commit::latest();       // No repo arg needed

// Get the full repo string (nullable)
Connector::repo();       // 'owner/repo' or null

// Get the full repo string (throws if not set)
Connector::

// Work on first repo
Connector::forRepo('acme/api');
Issue::all(); // Issues from acme/api

// Switch to different repo
Connector::forRepo('acme/web');
Issue::all(); // Now issues from acme/web

// Clear context entirely
Connector::clearRepo();
Connector::repo(); // null

use ConduitUi\GitHubConnector\Exceptions\NoRepoContextException;

try {
    // Throws if no context set
    $owner = Connector::owner();
} catch (NoRepoContextException $e) {
    // "No repository context set. Call Connector::forRepo() first."
}

// Or check first
if (Connector::repo() !== null) {
    $owner = Connector::owner();
}

// In your package (e.g., conduit-ui/issue)
class Issue
{
    public static function forRepo(string $repository): void
    {
        Connector::forRepo($repository);
    }

    public static function all(): Collection
    {
        $owner = Connector::owner();
        $repo = Connector::repoName();

        // Fetch issues using inherited context...
    }
}

// User can set context via any package
Issue::forRepo('owner/repo');

// Or directly on connector
Connector::forRepo('owner/repo');

// Either way, all packages inherit it
PullRequests::open()->get();
Commit::since(now()->subWeek());