Download the PHP package zero-to-prod/github-sdk without Composer
On this page you can find all versions of the php package zero-to-prod/github-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zero-to-prod/github-sdk
More information about zero-to-prod/github-sdk
Files in zero-to-prod/github-sdk
Package github-sdk
Short Description GitHub Sdk
License MIT
Homepage https://github.com/zero-to-prod/github-sdk
Informations about the package github-sdk
zero-to-prod/github-sdk
A PHP SDK for the GitHub REST API generated from GitHub's OpenAPI document.
Table of Contents
- Install
- Cli
- Basic Setup
- Authentication
- Find a method
- Query parameters
- Pagination
- Errors
- Lifecycle Hooks
- Hooks
- HookContext
- Retries
- Timeouts
- Caching responses
- Composing decorators
- Testing
- Fake transport
- Testing with
Http::fake() - Factories
- Publishing model factories
- Models
- Publishing models
- Extending
- Custom HttpTransport
- Agents
- Regenerating
Install
PHP 8.1 or newer, with ext-curl and ext-json.
Cli
Basic Setup
Positional arguments are used:
You can use an array as the body or use the provided request DTO.
Authentication
In this package you own the authentication. Set GitHubSdkConfig::headers for every request.
You can also override the headers of a single call with Options::headers.
You can setup functions for that hook into the request lifecycle.
Here is an example of a token that rotates mid-process.
Find a method
This package uses a simple verbResource naming convention:
getRepo,listRepoIssues,createRepoIssue- etc.
If you don't know the name of something, you can use the cli tools:
Query parameters
The query param can be defined this way:
Pagination
This SDK uses pagination with per_page and page, and returns the next link in a header.
Errors
The ApiResult is returned for every request.
Get the raw response with Options::raw.
Lifecycle Hooks
This package provides several lifecycle hooks to add your custom logic.
Hooks
| Hook | Key | Signature | Can mutate? | $response |
|---|---|---|---|---|
before |
Hook::before->value ('before') |
fn(HookContext): HookContext\|void |
Yes — return a HookContext to replace it |
null |
after |
Hook::after->value ('after') |
fn(HookContext): void |
No | the transport response |
onException |
Hook::onException->value ('onException') |
fn(HookContext, Throwable): void |
No | null |
HookContext
Lifecycle of a request:
Retries
You can wrap ny transport with RetryingHttpTransport.
Timeouts
Use CurlHttpTransport to set the connect timeout apart from the total.
Caching responses
Use CachingHttpTransport to wrap any transport and routes for GET requests through a closure.
This only applies to GET.
Example of in-memory caching:
Control the return type:
Setting up a fake transport:
Composing decorators
You can use decorators for HttpTransport so they can nest. Order matters here.
Testing
Fake transport
Use GitHubSdk::fake() to set up an in-memory fake for testing.
Use ApiRoute to render the route:
Testing with Http::fake()
Factories
There are three factories you can use for testing:
ErrorsFactory,PaginationFactory,GitHubSdkConfigFactory
->context() returns an array of the model.
Publishing model factories
Publish model factories in your project for testing:
Models
ApiResult::$data holds a hydrated model.
Publishing models
You can be selective with the publishing of models.
Configure the projects namespace:
Extending
| Plug point | How | Default |
|---|---|---|
| HTTP client | Pass an HttpTransport to the constructor |
CurlHttpTransport |
| Retries | Wrap the transport in RetryingHttpTransport |
None |
| Response caching | Wrap the transport in CachingHttpTransport |
None |
| Model namespace | GitHubSdkConfig::model_namespace + publish:models |
Zerotoprod\GitHubSdk\Models |
| Route set | GitHubSdkConfig::route_enum — any string-backed enum with #[AdminApi] |
ApiRoute |
| Factory namespace | publish:factories <namespace> [factory...] |
Zerotoprod\GitHubSdk\Factories |
| Response shape | [Options::raw => true] — skip ApiResult hydration |
ApiResult with $data / $errors |
| Request body | Typed request model or raw array | — |
| Headers, timeout | $options[Options::headers], $options['timeout'] |
— |
| Query params | $options[Options::query] |
— |
| Curl options | $options['curl'] (native CURLOPT_*) |
CurlHttpTransport only |
Custom HttpTransport
Implement Zerotoprod\GitHubSdk\HttpTransport.
Agents
publish:skill drops a skill into .claude/commands/.
publish:docs syncs the package docs into your project and wires composer post-install-cmd and post-update-cmd so they stay current.
Regenerating
src/Models/ and src/ApiRoute.php are generated. Do not hand-edit them.
The source is declared in sdk.json, and it is GitHub's published description.
All versions of github-sdk with dependencies
ext-curl Version *
ext-json Version *
zero-to-prod/data-model Version ^81.17
zero-to-prod/data-model-helper Version ^82.1
zero-to-prod/data-model-factory Version ^71.8.1