定制 oneduo/github-sdk-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oneduo/github-sdk-php

Composer 安装命令:

composer require oneduo/github-sdk-php

包简介

PHP SDK for the GitHub REST API – OpenAPI based and fully typed for seamless integration

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A fully typed, modern PHP client for the GitHub REST API v3, built on top of Saloon. This SDK provides a clean, intuitive, and fluent interface for interacting with all GitHub API endpoints, leveraging Saloon's powerful features for authentication, request building, and extensibility.

Installation

Install via Composer:

composer require oneduo/github-sdk-php

Documentation

Basic Usage

Initialize the Connector

use Oneduo\GitHubSdk\GitHubConnector;

$github = new GitHubConnector();

Example: Fetch a Public Repository (No Authentication Required)

$response = $github->repos()->get('octocat', 'hello-world');
$repository = $response->json();

Example: List Public Users (No Authentication Required)

$response = $github->users()->list();
$users = $response->json();

Example: Get User Information (No Authentication Required)

$response = $github->users()->getByUsername('octocat');
$user = $response->json();

Authentication

This SDK supports the most common authentication methods for the GitHub API using Saloon authenticators:

Bearer Token Authentication (Recommended for GitHub)

The TokenAuthenticator class adds an Authorization: Bearer header to requests:

use Saloon\Http\Auth\TokenAuthenticator;

$github = new GitHubConnector();
$github->authenticate(new TokenAuthenticator('your-github-token'));

// Now you can access authenticated endpoints
$response = $github->users()->getAuthenticated();
$user = $response->json();

Basic Auth (Base64 Encoded)

use Saloon\Http\Auth\BasicAuthenticator;

$github = new GitHubConnector();
$github->authenticate(new BasicAuthenticator('your-username', 'your-password'));

// Now you can access authenticated endpoints
$response = $github->users()->getAuthenticated();
$user = $response->json();

GitHub App Authentication

For GitHub Apps, you can use the included AppAuthenticator that generates JWT tokens:

use Oneduo\GitHubSdk\Authenticators\AppAuthenticator;

// Using a private key file path
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
    appId: 'your-app-id',
    key: '/path/to/your/private-key.pem'
));

// Or using key content directly  
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
    appId: 'your-app-id',
    key: '-----BEGIN RSA PRIVATE KEY-----...'
));

// With passphrase if your key is encrypted
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
    appId: 'your-app-id',
    key: '/path/to/your/private-key.pem',
    passphrase: 'your-passphrase'
));

// Using an existing OpenSSLAsymmetricKey resource (PHP 8.0+)
$keyResource = openssl_pkey_get_private(file_get_contents('/path/to/key.pem'));
$github = new GitHubConnector();
$github->authenticate(new AppAuthenticator(
    appId: 'your-app-id',
    key: $keyResource
));

// Now you can access GitHub App endpoints
$response = $github->apps()->getAuthenticated();
$app = $response->json();

The AppAuthenticator supports:

  • File paths: String path to your private key file
  • Key content: Raw private key content as a string
  • OpenSSL resources: OpenSSLAsymmetricKey objects (PHP 8.0+)
  • Passphrases: Optional encryption passphrase for protected keys

For more authentication strategies (query, certificate, header, multiple, custom, etc.), see the Saloon Authentication Documentation.

Advanced Usage

Example: List Repositories for an Organization

$github->authenticate(new TokenAuthenticator('your-github-token'));
$response = $github->repos()->listForOrg('oneduo');
$repos = $response->json();

Example: Create a Repository (Authenticated)

$github->authenticate(new TokenAuthenticator('your-github-token'));
$response = $github->repos()->createForAuthenticatedUser([
    'name' => 'my-new-repo',
    'private' => true,
]);
$newRepo = $response->json();

Custom Requests

You can send custom requests using Saloon's request system. For example, to call an undocumented or custom endpoint:

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

class MyCustomRequest extends Request {
    protected Method $method = Method::GET;
    
    public function resolveEndpoint(): string {
        return '/rate_limit';
    }
}

$response = $github->send(new MyCustomRequest());
$data = $response->json();

Tip

Explore Saloon's documentation for more on custom requests, plugins, and advanced features.

More Examples

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Contributions are welcome! Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

oneduo/github-sdk-php 适用场景与选型建议

oneduo/github-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 456 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「github」 「sdk」 「laravel」 「oneduo」 「github-sdk-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 oneduo/github-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 oneduo/github-sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 oneduo/github-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 456
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-06