2008-02-28 18:42:56 +00:00
|
|
|
<?php
|
2008-03-05 22:59:23 +00:00
|
|
|
/**
|
|
|
|
* Class Minify
|
|
|
|
* @package Minify
|
|
|
|
*/
|
2008-06-18 11:44:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Minify_Source
|
|
|
|
*/
|
|
|
|
require_once 'Minify/Source.php';
|
2008-03-05 22:59:23 +00:00
|
|
|
|
2008-02-28 18:42:56 +00:00
|
|
|
/**
|
|
|
|
* Minify - Combines, minifies, and caches JavaScript and CSS files on demand.
|
|
|
|
*
|
2008-02-29 01:36:05 +00:00
|
|
|
* See README for usage instructions (for now).
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
2008-06-18 11:44:39 +00:00
|
|
|
* This library was inspired by {@link mailto:flashkot@mail.ru jscsscomp by Maxim Martynyuk}
|
|
|
|
* and by the article {@link http://www.hunlock.com/blogs/Supercharged_Javascript "Supercharged JavaScript" by Patrick Hunlock}.
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
2008-03-27 16:04:45 +00:00
|
|
|
* Requires PHP 5.1.0.
|
|
|
|
* Tested on PHP 5.1.6.
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
|
|
|
* @package Minify
|
|
|
|
* @author Ryan Grove <ryan@wonko.com>
|
|
|
|
* @author Stephen Clay <steve@mrclay.org>
|
2008-03-04 17:04:09 +00:00
|
|
|
* @copyright 2008 Ryan Grove, Stephen Clay. All rights reserved.
|
2008-02-28 18:42:56 +00:00
|
|
|
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
|
|
|
* @link http://code.google.com/p/minify/
|
|
|
|
*/
|
|
|
|
class Minify {
|
|
|
|
|
2008-03-01 15:08:38 +00:00
|
|
|
const TYPE_CSS = 'text/css';
|
|
|
|
const TYPE_HTML = 'text/html';
|
2008-03-04 17:04:09 +00:00
|
|
|
// there is some debate over the ideal JS Content-Type, but this is the
|
|
|
|
// Apache default and what Yahoo! uses..
|
|
|
|
const TYPE_JS = 'application/x-javascript';
|
2008-03-01 15:08:38 +00:00
|
|
|
|
2008-07-29 03:48:10 +00:00
|
|
|
/**
|
|
|
|
* How many hours behind are the file modification times of uploaded files?
|
|
|
|
*
|
|
|
|
* The mtime of files on Windows can behind what they should be on the server.
|
|
|
|
* Immediately after modifying and uploading a file, use the touch command
|
|
|
|
* to update the mtime on the server. If the mtime jumps ahead by a
|
|
|
|
* number of hours, set this variable to that number. If the mtime moves back,
|
|
|
|
* this should not be needed.
|
|
|
|
*
|
|
|
|
* @var int $uploaderHoursBehind
|
|
|
|
*/
|
|
|
|
public static $uploaderHoursBehind = 0;
|
|
|
|
|
2008-02-28 18:42:56 +00:00
|
|
|
/**
|
2008-06-22 15:08:30 +00:00
|
|
|
* @see setCache()
|
|
|
|
* @param mixed $cache object with identical interface as Minify_Cache_File or
|
|
|
|
* a directory path. (default = '')
|
|
|
|
* @return null
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2008-08-12 01:55:35 +00:00
|
|
|
public static function useServerCache($path = '')
|
2008-06-22 15:08:30 +00:00
|
|
|
{
|
|
|
|
self::setCache($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify a cache object (with identical interface as Minify_Cache_File) or
|
|
|
|
* a path to use with Minify_Cache_File.
|
|
|
|
*
|
|
|
|
* If not called, Minify will not use a cache and, for each 200 response, will
|
|
|
|
* need to recombine files, minify and encode the output.
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
2008-06-22 15:08:30 +00:00
|
|
|
* @param mixed $cache object with identical interface as Minify_Cache_File or
|
|
|
|
* a directory path. (default = '')
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
|
|
|
* @return null
|
|
|
|
*/
|
2008-06-22 15:08:30 +00:00
|
|
|
public static function setCache($cache = '')
|
|
|
|
{
|
|
|
|
if (is_string($cache)) {
|
|
|
|
require_once 'Minify/Cache/File.php';
|
|
|
|
self::$_cache = new Minify_Cache_File($cache);
|
2008-03-27 16:04:45 +00:00
|
|
|
} else {
|
2008-06-22 15:08:30 +00:00
|
|
|
self::$_cache = $cache;
|
2008-03-27 16:04:45 +00:00
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|
2008-06-22 15:08:30 +00:00
|
|
|
|
|
|
|
private static $_cache = null;
|
2008-02-28 18:42:56 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-01 15:08:38 +00:00
|
|
|
* Serve a request for a minified file.
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
2008-03-01 15:08:38 +00:00
|
|
|
* Here are the available options and defaults in the base controller:
|
|
|
|
*
|
|
|
|
* 'isPublic' : send "public" instead of "private" in Cache-Control
|
|
|
|
* headers, allowing shared caches to cache the output. (default true)
|
|
|
|
*
|
2008-06-08 13:24:23 +00:00
|
|
|
* 'quiet' : set to true to have serve() return an array rather than sending
|
|
|
|
* any headers/output (default false)
|
2008-03-01 15:08:38 +00:00
|
|
|
*
|
|
|
|
* 'encodeOutput' : to disable content encoding, set this to false (default true)
|
|
|
|
*
|
|
|
|
* 'encodeMethod' : generally you should let this be determined by
|
|
|
|
* HTTP_Encoder (leave null), but you can force a particular encoding
|
2008-06-08 13:24:23 +00:00
|
|
|
* to be returned, by setting this to 'gzip', 'deflate', or '' (no encoding)
|
2008-03-01 15:08:38 +00:00
|
|
|
*
|
|
|
|
* 'encodeLevel' : level of encoding compression (0 to 9, default 9)
|
|
|
|
*
|
2008-06-09 23:29:38 +00:00
|
|
|
* 'contentTypeCharset' : appended to the Content-Type header sent. Set to a falsey
|
|
|
|
* value to remove. (default 'UTF-8')
|
2008-03-01 15:08:38 +00:00
|
|
|
*
|
2008-07-22 23:39:12 +00:00
|
|
|
* 'maxAge' : set this to the number of seconds the client should use its cache
|
|
|
|
* before revalidating with the server. This sets Cache-Control: max-age and the
|
|
|
|
* Expires header. Unlike the old 'setExpires' setting, this setting will NOT
|
|
|
|
* prevent conditional GETs. Note this has nothing to do with server-side caching.
|
2008-03-01 15:08:38 +00:00
|
|
|
*
|
2008-06-30 19:46:23 +00:00
|
|
|
* 'debug' : set to true to minify all sources with the 'Lines' controller, which
|
|
|
|
* eases the debugging of combined files. This also prevents 304 responses.
|
|
|
|
* @see Minify_Lines::minify()
|
|
|
|
*
|
2008-06-22 15:08:30 +00:00
|
|
|
* 'minifiers' : to override Minify's default choice of minifier function for
|
|
|
|
* a particular content-type, specify your callback under the key of the
|
|
|
|
* content-type:
|
2008-03-01 15:08:38 +00:00
|
|
|
* <code>
|
2008-06-22 15:08:30 +00:00
|
|
|
* // call customCssMinifier($css) for all CSS minification
|
|
|
|
* $options['minifiers'][Minify::TYPE_CSS] = 'customCssMinifier';
|
|
|
|
*
|
|
|
|
* // don't minify Javascript at all
|
|
|
|
* $options['minifiers'][Minify::TYPE_JS] = '';
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* 'minifierOptions' : to send options to the minifier function, specify your options
|
|
|
|
* under the key of the content-type. E.g. To send the CSS minifier an option:
|
|
|
|
* <code>
|
|
|
|
* // give CSS minifier array('optionName' => 'optionValue') as 2nd argument
|
|
|
|
* $options['minifierOptions'][Minify::TYPE_CSS]['optionName'] = 'optionValue';
|
2008-03-01 15:08:38 +00:00
|
|
|
* </code>
|
|
|
|
*
|
2008-08-12 01:55:35 +00:00
|
|
|
* 'contentType' : (optional) this is only needed if your file extension is not
|
|
|
|
* js/css/html. The given content-type will be sent regardless of source file
|
|
|
|
* extension, so this should not be used in a Groups config with other
|
|
|
|
* Javascript/CSS files.
|
|
|
|
*
|
2008-03-01 15:08:38 +00:00
|
|
|
* Any controller options are documented in that controller's setupSources() method.
|
2008-02-28 18:42:56 +00:00
|
|
|
*
|
2008-06-18 11:44:39 +00:00
|
|
|
* @param mixed instance of subclass of Minify_Controller_Base or string name of
|
|
|
|
* controller. E.g. 'Files'
|
|
|
|
*
|
|
|
|
* @param array $options controller/serve options
|
|
|
|
*
|
|
|
|
* @return mixed null, or, if the 'quiet' option is set to true, an array
|
|
|
|
* with keys "success" (bool), "statusCode" (int), "content" (string), and
|
|
|
|
* "headers" (array).
|
2008-08-12 01:55:35 +00:00
|
|
|
*
|
|
|
|
* @todo add option to auto-fix relative URIs in CSS (default = true)
|
2008-02-28 18:42:56 +00:00
|
|
|
*/
|
2008-03-01 15:08:38 +00:00
|
|
|
public static function serve($controller, $options = array()) {
|
|
|
|
if (is_string($controller)) {
|
|
|
|
// make $controller into object
|
|
|
|
$class = 'Minify_Controller_' . $controller;
|
|
|
|
if (! class_exists($class, false)) {
|
2008-06-28 20:23:29 +00:00
|
|
|
require_once "Minify/Controller/"
|
|
|
|
. str_replace('_', '/', $controller) . ".php";
|
2008-03-01 15:08:38 +00:00
|
|
|
}
|
|
|
|
$controller = new $class();
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up controller sources and mix remaining options with
|
|
|
|
// controller defaults
|
|
|
|
$options = $controller->setupSources($options);
|
|
|
|
$options = $controller->analyzeSources($options);
|
|
|
|
self::$_options = $controller->mixInDefaultOptions($options);
|
|
|
|
|
2008-07-22 23:39:12 +00:00
|
|
|
// check request validity
|
2008-03-01 15:08:38 +00:00
|
|
|
if (! $controller->sources) {
|
|
|
|
// invalid request!
|
|
|
|
if (! self::$_options['quiet']) {
|
|
|
|
header(self::$_options['badRequestHeader']);
|
|
|
|
echo self::$_options['badRequestHeader'];
|
2008-06-08 13:24:23 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
list(,$statusCode) = explode(' ', self::$_options['badRequestHeader']);
|
|
|
|
return array(
|
|
|
|
'success' => false
|
|
|
|
,'statusCode' => (int)$statusCode
|
|
|
|
,'content' => ''
|
|
|
|
,'headers' => array()
|
|
|
|
);
|
2008-03-01 15:08:38 +00:00
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|
2008-02-29 23:59:50 +00:00
|
|
|
|
2008-02-28 18:42:56 +00:00
|
|
|
self::$_controller = $controller;
|
2008-06-28 20:23:29 +00:00
|
|
|
|
|
|
|
if (self::$_options['debug']) {
|
|
|
|
self::_setupDebug($controller->sources);
|
2008-07-22 23:39:12 +00:00
|
|
|
self::$_options['maxAge'] = 0;
|
2008-06-28 20:23:29 +00:00
|
|
|
}
|
2008-07-22 23:39:12 +00:00
|
|
|
|
|
|
|
// check client cache
|
|
|
|
require_once 'HTTP/ConditionalGet.php';
|
|
|
|
$cgOptions = array(
|
|
|
|
'lastModifiedTime' => self::$_options['lastModifiedTime']
|
|
|
|
,'isPublic' => self::$_options['isPublic']
|
|
|
|
);
|
2008-07-29 03:48:10 +00:00
|
|
|
if (self::$_options['maxAge'] > 0) {
|
2008-07-22 23:39:12 +00:00
|
|
|
$cgOptions['maxAge'] = self::$_options['maxAge'];
|
|
|
|
}
|
|
|
|
$cg = new HTTP_ConditionalGet($cgOptions);
|
|
|
|
if ($cg->cacheIsValid) {
|
|
|
|
// client's cache is valid
|
|
|
|
if (! self::$_options['quiet']) {
|
|
|
|
$cg->sendHeaders();
|
|
|
|
return;
|
2008-06-08 13:24:23 +00:00
|
|
|
} else {
|
2008-07-22 23:39:12 +00:00
|
|
|
return array(
|
|
|
|
'success' => true
|
|
|
|
,'statusCode' => 304
|
|
|
|
,'content' => ''
|
|
|
|
,'headers' => $cg->getHeaders()
|
|
|
|
);
|
2008-03-03 16:23:39 +00:00
|
|
|
}
|
2008-06-08 13:24:23 +00:00
|
|
|
} else {
|
2008-07-22 23:39:12 +00:00
|
|
|
// client will need output
|
|
|
|
$headers = $cg->getHeaders();
|
|
|
|
unset($cg);
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|
2008-06-08 13:24:23 +00:00
|
|
|
|
2008-02-28 18:42:56 +00:00
|
|
|
// determine encoding
|
|
|
|
if (self::$_options['encodeOutput']) {
|
|
|
|
if (self::$_options['encodeMethod'] !== null) {
|
|
|
|
// controller specifically requested this
|
|
|
|
$contentEncoding = self::$_options['encodeMethod'];
|
|
|
|
} else {
|
|
|
|
// sniff request header
|
|
|
|
require_once 'HTTP/Encoder.php';
|
|
|
|
// depending on what the client accepts, $contentEncoding may be
|
2008-06-08 13:24:23 +00:00
|
|
|
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
|
|
|
|
// getAcceptedEncoding() with false leaves out compress as an option.
|
|
|
|
list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false);
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self::$_options['encodeMethod'] = ''; // identity (no encoding)
|
|
|
|
}
|
|
|
|
|
2008-07-22 23:39:12 +00:00
|
|
|
// check server cache
|
2008-06-22 15:08:30 +00:00
|
|
|
if (null !== self::$_cache) {
|
2008-06-08 13:24:23 +00:00
|
|
|
// using cache
|
|
|
|
// the goal is to use only the cache methods to sniff the length and
|
|
|
|
// output the content, as they do not require ever loading the file into
|
|
|
|
// memory.
|
2008-06-09 20:30:11 +00:00
|
|
|
$cacheId = 'minify_' . self::_getCacheId();
|
2008-06-08 13:24:23 +00:00
|
|
|
$encodingExtension = self::$_options['encodeMethod']
|
|
|
|
? ('deflate' === self::$_options['encodeMethod']
|
|
|
|
? '.zd'
|
|
|
|
: '.zg')
|
|
|
|
: '';
|
|
|
|
$fullCacheId = $cacheId . $encodingExtension;
|
|
|
|
// check cache for valid entry
|
2008-06-22 15:08:30 +00:00
|
|
|
$cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
|
|
|
|
if ($cacheIsReady) {
|
|
|
|
$cacheContentLength = self::$_cache->getSize($fullCacheId);
|
|
|
|
} else {
|
2008-06-08 13:24:23 +00:00
|
|
|
// generate & cache content
|
|
|
|
$content = self::_combineMinify();
|
2008-06-22 15:08:30 +00:00
|
|
|
self::$_cache->store($cacheId, $content);
|
|
|
|
self::$_cache->store($cacheId . '.zd', gzdeflate($content, self::$_options['encodeLevel']));
|
|
|
|
self::$_cache->store($cacheId . '.zg', gzencode($content, self::$_options['encodeLevel']));
|
2008-06-08 13:24:23 +00:00
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
} else {
|
2008-06-08 13:24:23 +00:00
|
|
|
// no cache
|
|
|
|
$cacheIsReady = false;
|
2008-02-28 18:42:56 +00:00
|
|
|
$content = self::_combineMinify();
|
|
|
|
}
|
2008-06-08 13:24:23 +00:00
|
|
|
if (! $cacheIsReady && self::$_options['encodeMethod']) {
|
|
|
|
// still need to encode
|
|
|
|
$content = ('deflate' === self::$_options['encodeMethod'])
|
|
|
|
? gzdeflate($content, self::$_options['encodeLevel'])
|
|
|
|
: gzencode($content, self::$_options['encodeLevel']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add headers
|
|
|
|
$headers['Content-Length'] = $cacheIsReady
|
|
|
|
? $cacheContentLength
|
|
|
|
: strlen($content);
|
2008-06-09 23:29:38 +00:00
|
|
|
$headers['Content-Type'] = self::$_options['contentTypeCharset']
|
2008-03-01 20:23:50 +00:00
|
|
|
? self::$_options['contentType'] . '; charset=' . self::$_options['contentTypeCharset']
|
2008-02-28 18:42:56 +00:00
|
|
|
: self::$_options['contentType'];
|
|
|
|
if (self::$_options['encodeMethod'] !== '') {
|
|
|
|
$headers['Content-Encoding'] = $contentEncoding;
|
|
|
|
$headers['Vary'] = 'Accept-Encoding';
|
|
|
|
}
|
|
|
|
|
2008-02-29 23:59:50 +00:00
|
|
|
if (! self::$_options['quiet']) {
|
|
|
|
// output headers & content
|
|
|
|
foreach ($headers as $name => $val) {
|
|
|
|
header($name . ': ' . $val);
|
|
|
|
}
|
2008-06-08 13:24:23 +00:00
|
|
|
if ($cacheIsReady) {
|
2008-06-22 15:08:30 +00:00
|
|
|
self::$_cache->display($fullCacheId);
|
2008-06-08 13:24:23 +00:00
|
|
|
} else {
|
|
|
|
echo $content;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return array(
|
|
|
|
'success' => true
|
|
|
|
,'statusCode' => 200
|
|
|
|
,'content' => $cacheIsReady
|
2008-06-22 15:08:30 +00:00
|
|
|
? self::$_cache->fetch($fullCacheId)
|
2008-06-08 13:24:23 +00:00
|
|
|
: $content
|
|
|
|
,'headers' => $headers
|
|
|
|
);
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Minify_Controller active controller for current request
|
|
|
|
*/
|
2008-03-03 16:23:39 +00:00
|
|
|
protected static $_controller = null;
|
2008-02-28 18:42:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array options for current request
|
|
|
|
*/
|
2008-03-03 16:23:39 +00:00
|
|
|
protected static $_options = null;
|
2008-02-28 18:42:56 +00:00
|
|
|
|
2008-06-28 20:23:29 +00:00
|
|
|
/**
|
|
|
|
* Set up sources to use Minify_Lines
|
|
|
|
*
|
|
|
|
* @param array $sources Minify_Source instances
|
2008-06-30 19:46:23 +00:00
|
|
|
*
|
|
|
|
* @return null
|
2008-06-28 20:23:29 +00:00
|
|
|
*/
|
|
|
|
protected static function _setupDebug($sources)
|
|
|
|
{
|
|
|
|
foreach ($sources as $source) {
|
|
|
|
$source->minifier = array('Minify_Lines', 'minify');
|
2008-06-30 19:46:23 +00:00
|
|
|
$id = $source->getId();
|
2008-06-28 20:23:29 +00:00
|
|
|
$source->minifyOptions = array(
|
2008-06-30 19:46:23 +00:00
|
|
|
'id' => (is_file($id) ? basename($id) : $id)
|
2008-06-28 20:23:29 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:42:56 +00:00
|
|
|
/**
|
|
|
|
* Combines sources and minifies the result.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-03-03 16:23:39 +00:00
|
|
|
protected static function _combineMinify() {
|
2008-02-28 18:42:56 +00:00
|
|
|
$type = self::$_options['contentType']; // ease readability
|
|
|
|
|
|
|
|
// when combining scripts, make sure all statements separated
|
2008-03-01 15:08:38 +00:00
|
|
|
$implodeSeparator = ($type === self::TYPE_JS)
|
2008-02-28 18:42:56 +00:00
|
|
|
? ';'
|
|
|
|
: '';
|
2008-03-01 15:08:38 +00:00
|
|
|
// allow the user to pass a particular array of options to each
|
|
|
|
// minifier (designated by type). source objects may still override
|
|
|
|
// these
|
2008-06-22 15:08:30 +00:00
|
|
|
$defaultOptions = isset(self::$_options['minifierOptions'][$type])
|
|
|
|
? self::$_options['minifierOptions'][$type]
|
2008-02-28 18:42:56 +00:00
|
|
|
: array();
|
2008-03-01 15:08:38 +00:00
|
|
|
// if minifier not set, default is no minification. source objects
|
|
|
|
// may still override this
|
2008-02-28 18:42:56 +00:00
|
|
|
$defaultMinifier = isset(self::$_options['minifiers'][$type])
|
|
|
|
? self::$_options['minifiers'][$type]
|
2008-02-29 22:18:16 +00:00
|
|
|
: false;
|
2008-02-28 18:42:56 +00:00
|
|
|
|
|
|
|
if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) {
|
|
|
|
// all source have same options/minifier, better performance
|
2008-03-01 15:08:38 +00:00
|
|
|
// to combine, then minify once
|
2008-02-28 18:42:56 +00:00
|
|
|
foreach (self::$_controller->sources as $source) {
|
|
|
|
$pieces[] = $source->getContent();
|
|
|
|
}
|
|
|
|
$content = implode($implodeSeparator, $pieces);
|
2008-02-29 22:18:16 +00:00
|
|
|
if ($defaultMinifier) {
|
|
|
|
self::$_controller->loadMinifier($defaultMinifier);
|
|
|
|
$content = call_user_func($defaultMinifier, $content, $defaultOptions);
|
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
} else {
|
2008-03-01 15:08:38 +00:00
|
|
|
// minify each source with its own options and minifier, then combine
|
2008-02-28 18:42:56 +00:00
|
|
|
foreach (self::$_controller->sources as $source) {
|
|
|
|
// allow the source to override our minifier and options
|
|
|
|
$minifier = (null !== $source->minifier)
|
|
|
|
? $source->minifier
|
|
|
|
: $defaultMinifier;
|
|
|
|
$options = (null !== $source->minifyOptions)
|
|
|
|
? array_merge($defaultOptions, $source->minifyOptions)
|
|
|
|
: $defaultOptions;
|
2008-02-29 22:18:16 +00:00
|
|
|
if ($defaultMinifier) {
|
|
|
|
self::$_controller->loadMinifier($minifier);
|
|
|
|
// get source content and minify it
|
|
|
|
$pieces[] = call_user_func($minifier, $source->getContent(), $options);
|
|
|
|
} else {
|
|
|
|
$pieces[] = $source->getContent();
|
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|
|
|
|
$content = implode($implodeSeparator, $pieces);
|
|
|
|
}
|
2008-03-02 04:59:13 +00:00
|
|
|
|
|
|
|
// do any post-processing (esp. for editing build URIs)
|
|
|
|
if (self::$_options['postprocessorRequire']) {
|
|
|
|
require_once self::$_options['postprocessorRequire'];
|
|
|
|
}
|
|
|
|
if (self::$_options['postprocessor']) {
|
|
|
|
$content = call_user_func(self::$_options['postprocessor'], $content, $type);
|
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a unique cache id for for this request.
|
|
|
|
*
|
|
|
|
* Any settings that could affect output are taken into consideration
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-03-03 16:23:39 +00:00
|
|
|
protected static function _getCacheId() {
|
2008-02-28 18:42:56 +00:00
|
|
|
return md5(serialize(array(
|
|
|
|
Minify_Source::getDigest(self::$_controller->sources)
|
|
|
|
,self::$_options['minifiers']
|
2008-08-16 22:13:28 +00:00
|
|
|
,self::$_options['minifierOptions']
|
|
|
|
,self::$_options['postprocessor']
|
2008-02-28 18:42:56 +00:00
|
|
|
)));
|
2008-06-22 15:08:30 +00:00
|
|
|
}
|
2008-02-28 18:42:56 +00:00
|
|
|
}
|