xlabs / cdnbundle
CDN 打包
5.0.0
2024-03-18 17:04 UTC
Requires
- php: >=7.2
- symfony/framework-bundle: >=5.0
README
CDN 包装引擎。
安装
通过 composer 安装
php -d memory_limit=-1 composer.phar require xlabs/cdnbundle
在您的 AppKernel 中
public function registerbundles()
{
return [
...
...
new XLabs\CDNBundle\XLabsCDNBundle(),
];
}
配置示例
以下显示默认值
# app/config/config.yml
x_labs_cdn:
providers:
highwinds:
account: ############
api_username: ############
api_password: ############
zones:
sample_public: {url: 'https://cdn.static.yourdomain.ext'}
sample_private: {url: 'https://cdn.yourdomain.ext', secretKey: '############', expiration_ttl: 7200}
sample_download: {url: 'https://cdn-file.yourdomain.ext', secretKey: '############', expiration_ttl: 7200}
...
default_zone: 'sample_public'
path_renaming: # optional
- { source: '^/my/path/', dest: '/cdn/rewrite/rule/path/'}
- { source: '...', dest: '...'}
provider2:
param1: #######
param2: #######
...
paramN: #######
...
用法
通过以下方式从 Controller 实例化服务
$this->get('xlabs_cdn')->...
用法 (TWIG)
通过以下方式从 twig 模板实例化服务
{{ getCDNResource({
'media_path' => '/path/to/my/asset.ext',
'zone' => false, // default_zone will be used if unset
'expiration_ttl' => 7200 // default ttl (7200) will be used if unset
}) }}
路径重命名
确保在 cdn vhost 中创建别名 as,以便 "/cdn/rewrite/rule/path/" 是 "/my/path/" 的别名。
路径剥离
例如,当使用 S3 存储,数据库中的资产可能包含路径 "media/project_name"。如果 CDN 区域已指向该 "media/project_name" 文件夹,则在签名 URL 之前需要从请求的资产中剥离。