softavis/flysystem-cloudflare
最新稳定版本:0.3.1
Composer 安装命令:
composer require softavis/flysystem-cloudflare
包简介
Flysystem Adapter for Cloudflare Images
README 文档
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.mdand 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.
统计信息
- 总下载量: 9.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-18