gufy / assets-services
资产管理服务提供商
v1.1.3
2013-12-15 12:29 UTC
Requires (Dev)
- silex/silex: ~1.1
- symfony/browser-kit: ~2.3
- symfony/css-selector: ~2.3
This package is auto-updated.
Last update: 2024-09-13 18:11:06 UTC
README
Silex 资产管理器
一个简单而有用的资产管理器。
安装
由于 Silex 使用 composer 作为其依赖项管理器,因此此资产管理器也是如此。只需在您的 composer.json 中提供此行
{
...
"require":{
...
"gufy/assets-service":"dev-master"
...
}
...
}
或参阅 https://packagist.org.cn/packages/gufy/assets-services 以获取更详细的可用版本信息
这是一个简单的 Silex 资产管理器。您需要做的很简单,在注册任何其他内容之前,只需注册服务提供者并提供一些参数即可。例如
<?php
$app = new Applicaton;
$app->register(new \Gufy\Service\Provider\AssetsServiceProvider,array(
'assets.js'=>array("... list of javascripts files ..."),
'assets.css'=>array("... list of css files ..."),
));
?>
可用选项
当您注册此提供者时,您可以在它上面提供一些配置。以下是一些配置选项
<?php
array(
'assets.options'=>array(
'baseUrl'=>'... your base url ...',// base url will prepend to all of the assets, i.e if you provide baseUrl with 'https://' and you have javascript file 'js/app.js' then, it will output as https:///js/app.js
// if you consider about combine and compress your assets, please provide this.
'combine'=>true, // set assets manager in combine mode
'basePath'=>'', // base directory path of your assets
'scriptPath'=>'', // set this variable with directory root of your webapp
'cachePath'=>'', // directory who handle your cached assets files
'cacheFileName'=>'', // custom file name of the cache file, leave blank or remove it and it will generated random string
),
);
或者,如果您更喜欢在运行时或在特定的响应中设置,可以使用这个
<?php
$app['assets']->setOption('optionName','...value...');
// example
$app['assets']->setOption('baseUrl','https:///hello-world/');
添加单个资产
如果您只想在控制器或特定的响应中添加文件,可以这样做。
<?php
$app->get('/',function(Request $request) use($app){
// for javascript file
$app['assets']->registerJs('... your file name ...');
// for css file
$app['assets']->registerCss('... your file name ...');
return "something";
});
动态添加自定义样式或 JavaScript
如果您想动态添加自定义样式或 JavaScript,请使用此。
<?php
$app->get('/',function(Request $request) use($app){
// for javascript file
$app['assets']->customJs('... $id ..','... $scripts ...');
// for css file
$app['assets']->customCss('... $styles ...');
return "something";
});
重置所有资产
要按类型重置,只需使用此函数即可
<?php
// reset javascript files
$app['assets']->reset('js');
// reset css files
$app['assets']->reset('css');
或者,如果您想重置所有资产,只需简单地使用此。
<?php
// reset the whole files
$app['assets']->reset();
贡献
如果您想为此存储库做出贡献,只需将其分支或从问题功能中给我一些反馈即可。