platformcommunity/flysystem-bunnycdn
Composer 安装命令:
composer require platformcommunity/flysystem-bunnycdn
包简介
Flysystem adapter for BunnyCDN
README 文档
README
Flysystem Adapter for BunnyCDN Storage
Installation
To install flysystem-bunnycdn, require the package with no version constraint. This should match the flysystem-bunnycdn version with your version of FlySystem (v2, v3 etc).
composer require platformcommunity/flysystem-bunnycdn "*"
Usage
use League\Flysystem\Filesystem; use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter; use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient; use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion; $adapter = new BunnyCDNAdapter( new BunnyCDNClient( 'storage-zone', 'api-key', BunnyCDNRegion::FALKENSTEIN ) ); // for temporary URL support, define a signing key $adapter->setTokenAuthKey('token-auth-signing-key'); $filesystem = new Filesystem($adapter);
Usage with Pull Zones
To have BunnyCDN adapter publish to a public CDN location, you have to a "Pull Zone" connected to your BunnyCDN Storage Zone. Add the full URL prefix of your Pull Zone (including http:///https://) to the BunnyCDNAdapter parameter like shown below.
$adapter = new BunnyCDNAdapter( new BunnyCDNClient( 'storage-zone', 'api-key', BunnyCDNRegion::FALKENSTEIN ), 'https://testing.b-cdn.net/' # Pull Zone URL ); // for temporary URL support, define a signing key $adapter->setTokenAuthKey('token-auth-signing-key'); $filesystem = new Filesystem($adapter);
Note: You can also use your own domain name if it's configured in the pull zone.
Once you add your pull zone, you can use the ->getUrl($path), or in Laravel, the ->url($path) command to get the fully qualified public URL of your BunnyCDN assets.
Usage in Laravel 9 & up
To add BunnyCDN adapter as a custom storage adapter in Laravel 9, install using the v3 composer installer.
composer require platformcommunity/flysystem-bunnycdn "^3.0"
Next, install the adapter to your AppServiceProvider to give Laravel's FileSystem knowledge of the BunnyCDN adapter.
/** * Bootstrap any application services. * * @return void */ public function boot() { Storage::extend('bunnycdn', function ($app, $config) { $adapter = new BunnyCDNAdapter( new BunnyCDNClient( $config['storage_zone'], $config['api_key'], $config['region'] ), $config['pull_zone'] ); // for temporary URL support, define a signing key $adapter->setTokenAuthKey('token-auth-signing-key'); return new FilesystemAdapter( new Filesystem($adapter, $config), $adapter, $config ); }); }
Finally, add the bunnycdn driver into your config/filesystems.php configuration file.
... 'bunnycdn' => [ 'driver' => 'bunnycdn', 'storage_zone' => env('BUNNYCDN_STORAGE_ZONE'), 'pull_zone' => env('BUNNYCDN_PULL_ZONE'), 'api_key' => env('BUNNYCDN_API_KEY'), 'token_auth_key' => env('BUNNYCDN_TOKEN_AUTH_KEY', ''), // optional if you'd like signed URLs 'region' => env('BUNNYCDN_REGION', \PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion::DEFAULT) ], ...
Lastly, populate your BUNNYCDN_STORAGE_ZONE, BUNNYCDN_API_KEY BUNNYCDN_REGION variables in your .env file.
BUNNYCDN_STORAGE_ZONE=testing_storage_zone BUNNYCDN_PULL_ZONE=https://testing.b-cdn.net BUNNYCDN_API_KEY="api-key" # BUNNYCDN_REGION=uk #BUNNYCDN_TOKEN_AUTH_KEY="your-token-auth-key" (optional, under CDN > Security > Token Authentication)
After that, you can use the bunnycdn disk in Laravel 9.
Storage::disk('bunnycdn')->put('index.html', '<html>Hello World</html>'); return response(Storage::disk('bunnycdn')->get('index.html'));
Note: You may have to run php artisan config:clear in order for your configuration to be refreshed if your app is running with a config cache driver / production mode.
Regions
For a full region list, please visit the BunnyCDN API documentation page.
flysystem-bunnycdn also comes with constants for each region located within PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion.
List of Regions
# Europe BunnyCDNRegion::FALKENSTEIN = 'de'; BunnyCDNRegion::STOCKHOLM = 'se'; # United Kingdom BunnyCDNRegion::UNITED_KINGDOM = 'uk'; # USA BunnyCDNRegion::NEW_YORK = 'ny'; BunnyCDNRegion::LOS_ANGELAS = 'la'; # SEA BunnyCDNRegion::SINGAPORE = 'sg'; # Oceania BunnyCDNRegion::SYDNEY = 'syd'; # Africa BunnyCDNRegion::JOHANNESBURG = 'jh'; # South America BunnyCDNRegion::BRAZIL = 'br';
Contributing
Pull requests welcome. Please feel free to lodge any issues as discussion points.
Development
Most of the understanding of how the Flysystem Adapter for BunnyCDN works comes from tests/. If you want to complete tests against a live BunnyCDN endpoint, copy the tests/ClientDI_Example.php to tests/ClientDI.php and insert your credentials into there. You can then run the whole suite by running vendor/bin/phpunit, or against a specific file by running vendor/bin/phpunit --bootstrap tests/ClientDI.php tests/ClientTest.php.
Licence
The Flysystem adapter for Bunny.net is licensed under MIT.
platformcommunity/flysystem-bunnycdn 适用场景与选型建议
platformcommunity/flysystem-bunnycdn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 487.71k 次下载、GitHub Stars 达 95, 最近一次更新时间为 2019 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 platformcommunity/flysystem-bunnycdn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 platformcommunity/flysystem-bunnycdn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 487.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 95
- 点击次数: 26
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-08