rhysr / zf2assetic
此包已被弃用且不再维护。未建议替代包。
Zend Framework 2 的 Assetic 模块
dev-master
2013-06-06 17:00 UTC
Requires
- kriswallsmith/assetic: 1.2.*@dev
- zendframework/zendframework: 2.*
Requires (Dev)
- phpunit/phpunit: 3.*
This package is not auto-updated.
Last update: 2022-02-01 12:24:39 UTC
README
Zend Framework 2 的 Assetic 模块
此模块以两种方式生成资源,一种是每次通过控制器请求创建资源,另一种是使用脚本生成资源到磁盘,然后由 web 服务器处理。
配置
所有配置都位于 zf2_assetic 数组中
return array( 'zf2_assetic' => array( 'useAssetController' => true, //use controller for asset, false means read from disk, recommend true for dev 'assetManifestPath' => __DIR__ . '/../data/asset-manifest.json', //path to a json file that maps the assetName to it's path on disk, generated by build script 'useCacheBuster' => true, // alter asset filename if file changes, to circumvent browser caching (optional, default: false) 'collections' => array( //array of all defined asset collections the module will provide 'base_css' => array( 'root' => __DIR__ . '/../assets/', //source directory for this collection's assets 'useCacheBuster' => false, // override the module level cache buster rule (optional) 'assets' => array( //list of assets to be compiled into collection 'css/test.css', ), 'filters' => array( 'AsseticCssRewriteFilter', //service manager name of assetic filters to apply ), 'options' => array( 'output' => 'base.css', //public path to collection ), ), ), ), );
资源预编译
当 useAssetController 为 true 时,assetPath 视图辅助器将生成基于磁盘的资源的路径。基于磁盘的资源需要通过命令行生成
php public/index.php assets dump
这将生成一个包含资源集合名称到路径映射的 json 清单文件,视图辅助器将使用它。当从磁盘提供编译后的资源时,Assetic 不再使用。
视图辅助器
模块有两个资产路径辅助器用于生成路径。useAssetController 标志确定创建哪个视图辅助器。一个服务于资产控制器,另一个从 json 资产清单中获取路径。
<link href="<?= $this->assetPath('base_css') ?>" media="screen" rel="stylesheet" type="text/css">
待办事项
- 控制台控制器需要测试
- 所有资产过滤器的工厂
- 过滤器工厂的参数,例如节点二进制路径