softavis / flysystem-cloudflare
Flysystem Adapter for Cloudflare Images
Installs: 2 692
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.2.5
- ext-fileinfo: *
- ext-json: *
- league/flysystem: ^2.1||^3.0
- symfony/http-client: ^5.4||^6.0||^7.0
- symfony/mime: ^5.4||^6.0||^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.56
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^9.6
README
Cloudflare images filesystem for Flysystem.
This library implement cloudflare images API to work with flysystem abstraction.
Cloudflare Images support only Image files, obviously
Installation
composer require softavis/flysystem-cloudflare
Usage
<?php declare(strict_types=1); use League\Flysystem\Config; use Softavis\Flysystem\Cloudflare\Client; use Softavis\Flysystem\Cloudflare\CloudflareAdapter; use Symfony\Component\HttpClient\HttpClient; require './vendor/autoload.php'; const CLOUDFLARE_API_KEY = 'your-cloudflare-access-token'; const CLOUDFLARE_ACCOUNT_ID = 'your-cloudflare-account-id'; const CLOUDFLARE_ACCOUNT_HASH = 'your-cloudflare-account-hash'; const CLOUDFLARE_VARIANT_NAME = 'your-cloudflare-images-variant'; const CLOUDFLARE_URL = 'https://api.cloudflare.com/client/v4/accounts/%s/images/'; $client = new Client(HttpClient::createForBaseUri(sprintf(CLOUDFLARE_URL, CLOUDFLARE_ACCOUNT_ID), [ 'auth_bearer' => CLOUDFLARE_API_KEY, ])); $adapter = new CloudflareAdapter($client); $flysystem = new League\Flysystem\Filesystem($adapter, [ 'accountHash' => CLOUDFLARE_ACCOUNT_HASH, 'variantName' => CLOUDFLARE_VARIANT_NAME ]); // see http://flysystem.thephpleague.com/api/ for full list of available functionality
Usage with Symfony
Add env's
CLOUDFLARE_API_KEY= CLOUDFLARE_ACCOUNT_ID= CLOUDFLARE_ACCOUNT_HASH= CLOUDFLARE_VARIANT_NAME=
First, add cloudflare scoped client (edit config/packages/framework.yaml) and add:
scoped_clients:
cloudflare.client:
base_uri: 'https://api.cloudflare.com/client/v4/accounts/%env(CLOUDFLARE_ACCOUNT_ID)%/images/'
auth_bearer: '%env(CLOUDFLARE_API_KEY)%'
Next, add cloudflare flysystem services (edit config/services.yaml):
cloudflare_adapter:
class: 'Softavis\Flysystem\Cloudflare\CloudflareAdapter'
arguments:
- '@cloudflare_client'
- '%env(CLOUDFLARE_ACCOUNT_HASH)%'
- '%env(CLOUDFLARE_VARIANT_NAME)%'
cloudflare_client:
class: 'Softavis\Flysystem\Cloudflare\Client'
arguments:
- '@cloudflare.client' # This argument is our scoped client
- '%env(CLOUDFLARE_ACCOUNT_HASH)%'
- '%env(CLOUDFLARE_VARIANT_NAME)%'
Last, add cloudflare_adapter to flysystem configuration (edit config/packages/flysystem.yaml)
flysystem:
storages:
default.storage:
adapter: 'cloudflare_adapter'
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Contributions are welcome and will be fully credited. We accept contributions via Pull Requests on Github.
Pull Requests
- PSR-2 Coding Standard - The easiest way to apply the conventions is to install PHP Code Sniffer.
- Document any change in behaviour - Make sure the
README.md
and any other relevant documentation are kept up-to-date. - Create feature branches - Don't ask us to pull from your master branch.
- One pull request per feature - If you want to do more than one thing, send multiple pull requests.
License
The MIT License (MIT). Please see License File for more information.