radiergummi / flysystem-github-storage
A GitHub Storage filesystem for Flysystem.
Requires
- php: >=7.2
- ext-json: *
- guzzlehttp/guzzle: ^6.5
- league/flysystem: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- psr/log: ^1.1
This package is auto-updated.
Last update: 2024-11-20 04:43:01 UTC
README
This is a GitHub adapter for Flysystem. It allows you to use a GitHub
repository as a storage backend for Flysystem.
It uses the Contents API of the GitHub API, version 3.
This adapter was heavily influenced by the marvelous work of Roy Voetman on his Gitlab Adapter. Make sure to check it out if you need a Gitlab integration instead.
Installation
composer require radiergummi/flysystem-github-storage
Usage
To use the GitHub storage with Flysystem, you'll need to create a client:
use Radiergummi\FlysystemGitHub\Client; $token = getenv('YOUR_GITHUB_ACCESS_TOKEN'); $repository = getenv('YOUR_GITHUB_REPOSITORY') $client = new Client($token, $repository);
You can then pass that client to the adapter:
use Radiergummi\FlysystemGitHub\GitHubAdapter; $adapter = new GitHubAdapter($client);
...and finally, create a Filesystem instance:
use League\Flysystem\Filesystem; $filesystem = new Filesystem($adapter);
Check out the Flysystem documentation for filesystem usage information.
Advanced usage
The library allows additional constructor arguments for the client:
Custom HTTP Client
You can optionally pass a custom Guzzle client for the library to use. If you do so, make sure to add the following default headers:
authorization
: Should contain your access token, eg.'authorization' => "token {$token}"
.content-type
: Should contain the desired API version, eg.'content-type' => "application/vnd.github.v3+json"
.
Contributions
Contributions are welcome! The test suite could be expanded and the error handling be improved - alas, the Flysystem
library does not support a sensible exception system but relies on 90s-style false
return values. While there's no way
around that, I'm sure one could improve the situation.