dkcwd/dkcwd-zf2-munee
Composer 安装命令:
composer require dkcwd/dkcwd-zf2-munee
包简介
Zend Framework 2 module leveraging 'munee' an asset optimisation library developed by Cody Lundquist. You can find munee at http://github.com/meenie/munee
README 文档
README
Maintenance Status for DkcwdZf2Munee:
Build Status for DkcwdZf2Munee:
Build Status for Munee by Cody Lundquist:
Purpose of the module
DkcwdZf2Munee is a Zend Framework 2 (ZF2) module which brings the joy of 'munee', an asset optimisation library developed by Cody Lundquist, to ZF2 applications. It is easy to implement and provides access to the features of munee through 3 ZF2 view helpers, 1 custom route and 1 simple controller.
Features of the module
- 3 ZF2 view helpers to correctly format munee requests
- 1 custom route to send munee requests to the munee controller
- 1 simple controller to handle munee requests
What is Munee?
A PHP5.3 library developed by Cody Lundquist to easily run all CSS through lessphp (LESS), resize/manipulate images on the fly, minify CSS and JS, and cache assets locally and remotely for lightening fast requests. See http://github.com/meenie/munee for more information. Some of the information below has been directly taken from the munee source repository.
Requirements
- PHP5.3.3+
- Composer for installing and updating all dependencies
- A Zend Framework 2 application you can use to work with the module
Composer Installation Instructions
Just for reference when using Composer, if you have a slow connection consider using COMPOSER_PROCESS_TIMEOUT=4000 prior to any php composer.phar commands to avoid a [Symfony\Component\Process\Exception\RuntimeException] The process timed out error. For example you may want to use COMPOSER_PROCESS_TIMEOUT=4000 php composer.phar update instead of php composer.phar update.
If you have a Zf2 project set up which you can use
-
Go to your main ZF2 application
composer.jsonfile and add"dkcwd/dkcwd-zf2-munee": "1.2.*"so as an example, if you are using the ZendSkeletonApplication and if no other requirements are meant to be specified in your main composer.json file, the composer.json file should be updated to look like this:{ "name": "zendframework/skeleton-application", "description": "Skeleton Application for ZF2", "license": "BSD-3-Clause", "keywords": [ "framework", "zf2" ], "homepage": "http://framework.zend.com/", "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.*", "dkcwd/dkcwd-zf2-munee": "1.2.*" } } -
Run
curl -s http://getcomposer.org/installer | php -
Run
php composer.phar update -
Once the installation is complete go to your ZF2
application.config.phpfile and add'DkcwdZf2Munee'to the list of modules. As an example assuming no other modules are in use except for theApplicationmodule which comes with the ZendSkeletonApplication it would look like this:<?php return array( 'modules' => array( 'Application', 'DkcwdZf2Munee' ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' => array( './module', './vendor', ), ), ); -
Make sure the
cachefolder insidevendor/meenie/muneeis writable or else it won't work
If you do not have a Zf2 project set up which you can use
-
cd to the directory you want to create your new ZF2 project in
-
Run
curl -s https://getcomposer.org/installer | php -
Run
php composer.phar create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application full/path/to/new/project/project-name -
You may want to run
php composer.phar self-updateif you saw a warning message -
Go to the
composer.jsonfile in the top level of your new ZF2 project folder and make it look like this:{ "name": "zendframework/skeleton-application", "description": "Skeleton Application for ZF2", "license": "BSD-3-Clause", "keywords": [ "framework", "zf2" ], "homepage": "http://framework.zend.com/", "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.*", "dkcwd/dkcwd-zf2-munee": "1.2.*" } } -
Run
php composer.phar update -
Once the installation is complete go to your ZF2
application.config.phpfile and add'DkcwdZf2Munee'to the list of modules. As an example assuming no other modules are in use except for theApplicationmodule which comes with the ZendSkeletonApplication it would look like this:<?php return array( 'modules' => array( 'Application', 'DkcwdZf2Munee' ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' => array( './module', './vendor', ), ), ); -
Make sure the
cachefolder insidevendor/meenie/muneeis writable or else it won't work
Usage Instructions
View Helpers
The functionality provided by munee is accessed using view helpers in your ZF2 application view scripts. There are 3 view helpers:
- MuneeCss($arrayOfCssFiles, $minify = true) for working with CSS files
- MuneeImg($pathToImage, $resizeParams, $anyAdditionalHtmlAttibutes = null) for working with images
- MuneeJs($arrayOfJsFiles, $minify = true) for working with Js files
The most likely place you will use the CSS and Js view helpers is within your layout script for generating a correctly formatted link to aggregate all your css and javascript files.
MuneeCss: One Request For All CSS with auto minification
All LESS files are automatically compiled through lessphp and cached, there is nothing extra that you need to do. Any changes you make to your CSS, even LESS files you have @import will automatically recreate the cache, invalidate the client side cache, and force the browser to download the newest version.
Example usage: In your view script do
echo $this->muneeCss(array('/css/style.css', '/css/other-style.css'));
to output a formatted stylesheet link which will allow all css files specified to be handled and minified in one request, alternatively you can do
echo $this->muneeCss(array('/css/style.css', '/css/other-style.css'), false);
for the same result but without minification.
MuneeImg: Handling/Resizing Images
Using Munee, you resize/crop/stretch/fill images on-the-fly using a set of parameters. The resulting image will be cached and served up on subsequent requests. If the source image is modified, it will recreate the cache then invalidate the client side cache and force the browser to download the newest version.
Example usage: In your view script do
echo $this->muneeImg('path-to-image.jpg', 'w[100]h[100]');
to output a formatted request using the chosen resize parameters. You can specify any additional image attributes such as an id or class by supplying an array full of key value pairs as a third parameter like this: array('class' => 'myImageClass', 'rel' => 'someTrigger')
Resize Parameters - Parameters can either be in long form or use their shortened form. The value for an alias must be wrapped in square brackets []. There is no need to put any characters between each parameter, although you can if you want.
height(orh) - The max height you want the image. Value must be an integer.width(orw) - The max width you want the image. Value must be an integer.exact(ore) - Crop the image to the exactheightandwidth. Value can betrueorfalse.stretch(ors) - Stretch the image to match the exactheightandwidth. Value can betrueorfalse.fill(orf) - Draw a background the exact size of theheightandwidthand centre the image in the middle. (If you do not want the image to be stretched, then do not use thestretchparameter along withfill). Value can betrueorfalse.fillColour(orfc) - The colour of the background. Default isFFFFFF(white). This can be any hex colour (i.e.FF0000)quality(orq) - JPEG compression value. Default is:75- It will only work for JPEG's.
MuneeJs: One Request For All JS with auto minification
All JavaScript is served through Munee so that it can handle the client side caching.
Example usage: In your view script do
echo $this->muneeJs(array('/js/script1.js', '/js/script2.js'));
to output a formatted script link which will allow all js files specified to be handled and minified in one request, alternatively you can do
echo $this->muneeCss(array('/js/script1.js', '/js/script2.js'), false);
for the same result but without minification.
Hope you enjoy using this module :-)
dkcwd/dkcwd-zf2-munee 适用场景与选型建议
dkcwd/dkcwd-zf2-munee 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.14k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2012 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「javascript」 「css」 「zf2」 「module」 「less」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dkcwd/dkcwd-zf2-munee 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dkcwd/dkcwd-zf2-munee 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dkcwd/dkcwd-zf2-munee 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 2.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-12-21