mirror of
https://github.com/mrclay/minify.git
synced 2025-09-19 10:21:31 +02:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3c11ba8232 | ||
|
ecbb5ae376 | ||
|
bd9a450694 | ||
|
bceffd5afb | ||
|
153e08b5a0 | ||
|
ce109925aa | ||
|
a0c5ecb514 | ||
|
6b469640a7 | ||
|
fb3931f8cd | ||
|
50488ce207 | ||
|
ebc91b5d33 | ||
|
e7728405f5 | ||
|
537b4b314a | ||
|
4a884a381f | ||
|
b018c834da | ||
|
27b4f758bc | ||
|
9231aed49f | ||
|
ea7fe90554 | ||
|
5ceada8a22 | ||
|
66f2622705 | ||
|
f3a408fd74 | ||
|
c60b6a2984 | ||
|
54a53c9c19 |
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@@ -0,0 +1,19 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
|
||||
; temporary
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.php]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
|
||||
[vendor/**]
|
||||
; Use editor default (possible autodetection).
|
||||
indent_style =
|
||||
indent_size =
|
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/.editorconfig export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/min_extras export-ignore
|
||||
/min_unit_tests export-ignore
|
@@ -1,5 +1,8 @@
|
||||
Minify Release History
|
||||
|
||||
(master)
|
||||
* Builder styled with Bootstrap (thanks to help from acidvertigo)
|
||||
|
||||
Version 2.2.0
|
||||
* Fix handling of RegEx in certain situations in JSMin
|
||||
* Thanks to Vovan-VE for reporting this
|
||||
|
@@ -16,11 +16,17 @@
|
||||
"issues": "http://code.google.com/p/minify/issues/list",
|
||||
"wiki": "http://code.google.com/p/minify/w/list"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": ["min/lib/"]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.1",
|
||||
"ext-pcre": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": ["min/lib/"]
|
||||
"require-dev": {
|
||||
"tubalmartin/cssmin": "~2.4.8"
|
||||
},
|
||||
"suggest": {
|
||||
"tubalmartin/cssmin": "Support minify with CSSMin (YUI PHP port)"
|
||||
}
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@ var MUB = {
|
||||
*/
|
||||
newLi : function () {
|
||||
return '<li id="li' + MUB._uid + '">http://' + location.host + '/<input type=text size=20>' +
|
||||
' <button title="Remove">x</button> <button title="Include Earlier">↑</button>' +
|
||||
' <button title="Include Later">↓</button> <span></span></li>';
|
||||
' <button class="btn btn-danger btn-sm" title="Remove">x</button> <button class="btn btn-default btn-sm" title="Include Earlier">↑</button>' +
|
||||
' <button class="btn btn-default btn-sm" title="Include Later">↓</button> <span></span></li>';
|
||||
},
|
||||
/**
|
||||
* Add new empty source LI and attach handlers to buttons
|
||||
@@ -36,13 +36,13 @@ var MUB = {
|
||||
$('#sources').append(MUB.newLi());
|
||||
var li = $('#li' + MUB._uid)[0];
|
||||
$('button[title=Remove]', li).click(function () {
|
||||
$('#results').hide();
|
||||
$('#results').addClass('hide');
|
||||
var hadValue = !!$('input', li)[0].value;
|
||||
$(li).remove();
|
||||
});
|
||||
$('button[title$=Earlier]', li).click(function () {
|
||||
$(li).prev('li').find('input').each(function () {
|
||||
$('#results').hide();
|
||||
$('#results').addClass('hide');
|
||||
// this = previous li input
|
||||
var tmp = this.value;
|
||||
this.value = $('input', li).val();
|
||||
@@ -52,7 +52,7 @@ var MUB = {
|
||||
});
|
||||
$('button[title$=Later]', li).click(function () {
|
||||
$(li).next('li').find('input').each(function () {
|
||||
$('#results').hide();
|
||||
$('#results').addClass('hide');
|
||||
// this = next li input
|
||||
var tmp = this.value;
|
||||
this.value = $('input', li).val();
|
||||
@@ -77,9 +77,9 @@ var MUB = {
|
||||
url : url,
|
||||
complete : function (xhr, stat) {
|
||||
if ('success' === stat)
|
||||
$('span', li).html('✓');
|
||||
$('span', li).html('<a href="#" class="btn btn-success btn-sm disabled">✓</a>');
|
||||
else {
|
||||
$('span', li).html('<button><b>404! </b> recheck</button>')
|
||||
$('span', li).html('<button class="btn btn-warning btn-sm"><b>404! </b> recheck</button>')
|
||||
.find('button').click(function () {
|
||||
MUB.liUpdateTestLink.call(li);
|
||||
});
|
||||
@@ -184,16 +184,16 @@ var MUB = {
|
||||
markup = '<link type="text/css" rel="stylesheet" href="' + uriH + '" />';
|
||||
}
|
||||
$('#uriHtml').val(markup);
|
||||
$('#results').show();
|
||||
$('#results').removeClass('hide');
|
||||
},
|
||||
/**
|
||||
* Handler for the "Add file +" button
|
||||
*/
|
||||
addButtonClick : function () {
|
||||
$('#results').hide();
|
||||
$('#results').addClass('hide');
|
||||
MUB.addLi();
|
||||
MUB.updateAllTestLinks();
|
||||
$('#update').show().click(MUB.update);
|
||||
$('#update').removeClass('hide').click(MUB.update);
|
||||
$('#sources li:last input')[0].focus();
|
||||
},
|
||||
/**
|
||||
@@ -201,7 +201,7 @@ var MUB = {
|
||||
*/
|
||||
init : function () {
|
||||
$('#jsDidntLoad').remove();
|
||||
$('#app').show();
|
||||
$('#app').removeClass('hide');
|
||||
$('#sources').html('');
|
||||
$('#add button').click(MUB.addButtonClick);
|
||||
// make easier to copy text out of
|
||||
@@ -213,7 +213,7 @@ var MUB = {
|
||||
$('a.ext').attr({target:'_blank'});
|
||||
if (location.hash) {
|
||||
// make links out of URIs from bookmarklet
|
||||
$('#getBm').hide();
|
||||
$('#getBm').addClass('hide');
|
||||
var i = 0, found = location.hash.substr(1).split(','), l = found.length;
|
||||
$('#bmUris').html('<p><strong>Found by bookmarklet:</strong> /</p>');
|
||||
var $p = $('#bmUris p');
|
||||
@@ -227,7 +227,7 @@ var MUB = {
|
||||
MUB.addButtonClick();
|
||||
$('#sources li:last input').val(this.innerHTML);
|
||||
MUB.liUpdateTestLink.call($('#sources li:last')[0]);
|
||||
$('#results').hide();
|
||||
$('#results').addClass('hide');
|
||||
return false;
|
||||
}).attr({title:'Add file +'});
|
||||
} else {
|
||||
|
@@ -49,6 +49,7 @@ ob_start();
|
||||
<!DOCTYPE html>
|
||||
<title>Minify URI Builder</title>
|
||||
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
|
||||
<style>
|
||||
body {margin:1em 60px;}
|
||||
h1, h2, h3 {margin-left:-25px; position:relative;}
|
||||
@@ -111,7 +112,7 @@ and click [Update].</p>
|
||||
|
||||
<div id=bmUris></div>
|
||||
|
||||
<p><button id=update class=hide>Update</button></p>
|
||||
<p><button class="btn btn-primary" id=update class=hide>Update</button></p>
|
||||
|
||||
<div id=results class=hide>
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/**
|
||||
* AJAX checks for zlib.output_compression
|
||||
*
|
||||
@@ -11,7 +11,7 @@ $_oc = ini_get('zlib.output_compression');
|
||||
require dirname(__FILE__) . '/../config.php';
|
||||
if (! $min_enableBuilder) {
|
||||
header('Location: /');
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['hello'])) {
|
||||
@@ -26,8 +26,8 @@ if (isset($_GET['hello'])) {
|
||||
'content' => 'World!'
|
||||
,'method' => 'deflate'
|
||||
));
|
||||
$he->encode();
|
||||
$he->sendAll();
|
||||
$he->encode();
|
||||
$he->sendAll();
|
||||
|
||||
} else {
|
||||
// echo status "0" or "1"
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
exit();
|
||||
exit;
|
||||
/* currently unused.
|
||||
|
||||
// capture PHP's default setting (may get overridden in config
|
||||
@@ -8,7 +8,7 @@ $_oc = ini_get('zlib.output_compression');
|
||||
// allow access only if builder is enabled
|
||||
require dirname(__FILE__) . '/../config.php';
|
||||
if (! $min_enableBuilder) {
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['oc'])) {
|
||||
|
@@ -52,6 +52,7 @@ $min_allowDebugFlag = false;
|
||||
//$min_cachePath = 'c:\\WINDOWS\\Temp';
|
||||
//$min_cachePath = '/tmp';
|
||||
//$min_cachePath = preg_replace('/^\\d+;/', '', session_save_path());
|
||||
|
||||
/**
|
||||
* To use APC/Memcache/ZendPlatform for cache storage, require the class and
|
||||
* set $min_cachePath to an instance. Example below:
|
||||
|
@@ -79,8 +79,8 @@ if (isset($_GET['f']) || isset($_GET['g'])) {
|
||||
|
||||
} elseif ($min_enableBuilder) {
|
||||
header('Location: builder/');
|
||||
exit();
|
||||
exit;
|
||||
} else {
|
||||
header("Location: /");
|
||||
exit();
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*!
|
||||
* cssmin.php 2.4.8-2
|
||||
* cssmin.php v2.4.8-4
|
||||
* Author: Tubal Martin - http://tubalmartin.me/
|
||||
* Repo: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
|
||||
*
|
||||
@@ -107,7 +107,7 @@ class CSSmin
|
||||
$l = strlen($css);
|
||||
|
||||
|
||||
// if the number of characters is 25000 or less, do not chunk
|
||||
// if the number of characters is 5000 or less, do not chunk
|
||||
if ($l <= $css_chunk_length) {
|
||||
$css_chunks[] = $css;
|
||||
} else {
|
||||
@@ -291,7 +291,7 @@ class CSSmin
|
||||
// Remove the spaces before the things that should not have spaces before them.
|
||||
// But, be careful not to turn "p :link {...}" into "p:link{...}"
|
||||
// Swap out any pseudo-class colons with the token, and then swap back.
|
||||
$css = preg_replace_callback('/(?:^|\})(?:(?:[^\{\:])+\:)+(?:[^\{]*\{)/', array($this, 'replace_colon'), $css);
|
||||
$css = preg_replace_callback('/(?:^|\})[^\{]*\s+\:/', array($this, 'replace_colon'), $css);
|
||||
|
||||
// Remove spaces before the things that should not have spaces before them.
|
||||
$css = preg_replace('/\s+([\!\{\}\;\:\>\+\(\)\]\~\=,])/', '$1', $css);
|
||||
@@ -336,11 +336,13 @@ class CSSmin
|
||||
// to avoid issues on Symbian S60 3.x browsers.
|
||||
$css = preg_replace('/(\*[a-z0-9\-]+\s*\:[^;\}]+)(\})/', '$1;$2', $css);
|
||||
|
||||
// Replace 0 length units 0(px,em,%) with 0.
|
||||
$css = preg_replace('/(^|[^0-9])(?:0?\.)?0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%|deg|g?rad|m?s|k?hz)/iS', '${1}0', $css);
|
||||
// Replace 0 <length> and 0 <percentage> values with 0.
|
||||
// <length> data type: https://developer.mozilla.org/en-US/docs/Web/CSS/length
|
||||
// <percentage> data type: https://developer.mozilla.org/en-US/docs/Web/CSS/percentage
|
||||
$css = preg_replace('/([^\\\\]\:|\s)0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%)/iS', '${1}0', $css);
|
||||
|
||||
// 0% step in a keyframe? restore the % unit
|
||||
$css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]*?\{)(.*?\}\s*\})/iS', array($this, 'replace_keyframe_zero'), $css);
|
||||
$css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]+\{)(.*?)(\}\})/iS', array($this, 'replace_keyframe_zero'), $css);
|
||||
|
||||
// Replace 0 0; or 0 0 0; or 0 0 0 0; with 0.
|
||||
$css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css);
|
||||
@@ -596,7 +598,7 @@ class CSSmin
|
||||
|
||||
private function replace_keyframe_zero($matches)
|
||||
{
|
||||
return $matches[1] . preg_replace('/0\s*,/', '0%,', preg_replace('/\s*0\s*\{/', '0%{', $matches[2]));
|
||||
return $matches[1] . preg_replace('/0(\{|,[^\)\{]+\{)/', '0%$1', $matches[2]) . $matches[3];
|
||||
}
|
||||
|
||||
private function rgb_to_hex($matches)
|
||||
|
@@ -435,7 +435,7 @@ class Minify {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo "<h1>$h1</h1>";
|
||||
echo "<p>Please see <a href='$url'>$url</a>.</p>";
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -70,7 +70,7 @@ class Minify_CSS_UriRewriter {
|
||||
// rewrite
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
return $css;
|
||||
@@ -94,7 +94,7 @@ class Minify_CSS_UriRewriter {
|
||||
// append
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
$css = preg_replace_callback('/url\\(\\s*([\'"](.*?)[\'"]|[^\\)\\s]+)\\s*\\)/'
|
||||
,array(self::$className, '_processUriCB'), $css);
|
||||
|
||||
self::$_prependPath = null;
|
||||
|
@@ -98,6 +98,9 @@ class Minify_Cache_File {
|
||||
{
|
||||
if ($this->_locking) {
|
||||
$fp = fopen($this->_path . '/' . $id, 'rb');
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
flock($fp, LOCK_SH);
|
||||
$ret = stream_get_contents($fp);
|
||||
flock($fp, LOCK_UN);
|
||||
|
130
min/lib/Minify/Cache/WinCache.php
Normal file
130
min/lib/Minify/Cache/WinCache.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Cache_Wincache
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* WinCache-based cache class for Minify
|
||||
*
|
||||
* <code>
|
||||
* Minify::setCache(new Minify_Cache_WinCache());
|
||||
* </code>
|
||||
*
|
||||
* @package Minify
|
||||
* @author Matthias Fax
|
||||
**/
|
||||
class Minify_Cache_WinCache
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a Minify_Cache_Wincache object, to be passed to
|
||||
* Minify::setCache().
|
||||
*
|
||||
*
|
||||
* @param int $expire seconds until expiration (default = 0
|
||||
* meaning the item will not get an expiration date)
|
||||
*/
|
||||
public function __construct($expire = 0)
|
||||
{
|
||||
if (!function_exists('wincache_ucache_info')) {
|
||||
throw new Exception("WinCache for PHP is not installed to be able to use Minify_Cache_WinCache!");
|
||||
}
|
||||
$this->_exp = $expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to cache.
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
return wincache_ucache_set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of a cache entry
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return int size in bytes
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
if (!$this->_fetch($id)) {
|
||||
return false;
|
||||
}
|
||||
return (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2)) ? mb_strlen($this->_data, '8bit') : strlen($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a valid cache entry exist?
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param int $srcMtime mtime of the original source file(s)
|
||||
*
|
||||
* @return bool exists
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cached content to output
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
echo $this->_fetch($id) ? $this->_data : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached content
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->_fetch($id) ? $this->_data : '';
|
||||
}
|
||||
|
||||
private $_exp = NULL;
|
||||
|
||||
// cache of most recently fetched id
|
||||
private $_lm = NULL;
|
||||
private $_data = NULL;
|
||||
private $_id = NULL;
|
||||
|
||||
/**
|
||||
* Fetch data and timestamp from WinCache, store in instance
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
private function _fetch($id)
|
||||
{
|
||||
if ($this->_id === $id) {
|
||||
return true;
|
||||
}
|
||||
$suc = false;
|
||||
$ret = wincache_ucache_get($id, $suc);
|
||||
if (!$suc) {
|
||||
$this->_id = NULL;
|
||||
return false;
|
||||
}
|
||||
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
||||
$this->_id = $id;
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -33,6 +33,11 @@
|
||||
*/
|
||||
class Minify_ClosureCompiler {
|
||||
|
||||
const OPTION_CHARSET = 'charset';
|
||||
const OPTION_COMPILATION_LEVEL = 'compilation_level';
|
||||
|
||||
public static $isDebug = false;
|
||||
|
||||
/**
|
||||
* Filepath of the Closure Compiler jar file. This must be set before
|
||||
* calling minifyJs().
|
||||
@@ -65,18 +70,28 @@ class Minify_ClosureCompiler {
|
||||
* @see https://code.google.com/p/closure-compiler/source/browse/trunk/README
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Minify_ClosureCompiler_Exception
|
||||
*/
|
||||
public static function minify($js, $options = array())
|
||||
{
|
||||
self::_prepare();
|
||||
if (! ($tmpFile = tempnam(self::$tempDir, 'cc_'))) {
|
||||
throw new Exception('Minify_ClosureCompiler : could not create temp file in "'.self::$tempDir.'".');
|
||||
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : could not create temp file in "'.self::$tempDir.'".');
|
||||
}
|
||||
file_put_contents($tmpFile, $js);
|
||||
exec(self::_getCmd($options, $tmpFile), $output, $result_code);
|
||||
$cmd = self::_getCmd($options, $tmpFile);
|
||||
exec($cmd, $output, $result_code);
|
||||
unlink($tmpFile);
|
||||
if ($result_code != 0) {
|
||||
throw new Exception('Minify_ClosureCompiler : Closure Compiler execution failed.');
|
||||
$message = 'Minify_ClosureCompiler : Closure Compiler execution failed.';
|
||||
if (self::$isDebug) {
|
||||
exec($cmd . ' 2>&1', $error);
|
||||
if ($error) {
|
||||
$message .= "\nReason:\n" . join("\n", $error);
|
||||
}
|
||||
}
|
||||
throw new Minify_ClosureCompiler_Exception($message);
|
||||
}
|
||||
return implode("\n", $output);
|
||||
}
|
||||
@@ -85,17 +100,18 @@ class Minify_ClosureCompiler {
|
||||
{
|
||||
$o = array_merge(
|
||||
array(
|
||||
'charset' => 'utf-8',
|
||||
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
|
||||
self::OPTION_CHARSET => 'utf-8',
|
||||
self::OPTION_COMPILATION_LEVEL => 'SIMPLE_OPTIMIZATIONS',
|
||||
),
|
||||
$userOptions
|
||||
);
|
||||
$charsetOption = $o[self::OPTION_CHARSET];
|
||||
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
|
||||
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
|
||||
? " --charset {$o['charset']}"
|
||||
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $charsetOption)
|
||||
? " --charset {$charsetOption}"
|
||||
: '');
|
||||
|
||||
foreach (array('compilation_level') as $opt) {
|
||||
foreach (array(self::OPTION_COMPILATION_LEVEL) as $opt) {
|
||||
if ($o[$opt]) {
|
||||
$cmd .= " --{$opt} ". escapeshellarg($o[$opt]);
|
||||
}
|
||||
@@ -106,18 +122,18 @@ class Minify_ClosureCompiler {
|
||||
private static function _prepare()
|
||||
{
|
||||
if (! is_file(self::$jarFile)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
|
||||
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
|
||||
}
|
||||
if (! is_readable(self::$jarFile)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
|
||||
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
|
||||
}
|
||||
if (! is_dir(self::$tempDir)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
|
||||
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
|
||||
}
|
||||
if (! is_writable(self::$tempDir)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
|
||||
throw new Minify_ClosureCompiler_Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:ts=4:sw=4:et */
|
||||
class Minify_ClosureCompiler_Exception extends Exception {}
|
||||
|
@@ -49,7 +49,6 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
$this->log("Duplicate group key found.");
|
||||
return $options;
|
||||
}
|
||||
$keys = explode(',', $_GET['g']);
|
||||
foreach ($keys as $key) {
|
||||
if (! isset($cOptions['groups'][$key])) {
|
||||
$this->log("A group configuration for \"{$key}\" was not found");
|
||||
|
@@ -44,7 +44,7 @@ if (isset($_POST['method']) && $_POST['method'] === 'Minify and serve') {
|
||||
} catch (Exception $e) {
|
||||
echo h($e->getMessage());
|
||||
}
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
$tpl = array();
|
||||
|
@@ -12,3 +12,6 @@ foo {background:url('/_test_files/css_uriRewriter/bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(foo:bar);} /* scheme, should not alter */
|
||||
foo {background:url("/_test_files/css_uriRewriter/foo bar.jpg");}
|
||||
@import url('/_test_files/css_uriRewriter/foo bar.css');
|
||||
@import "/_test_files/css_uriRewriter/foo bar.css";
|
||||
|
@@ -12,3 +12,6 @@ foo {background:url('http://cnd.com/A/B/bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(foo:bar);} /* scheme, should not alter */
|
||||
foo {background:url("http://cnd.com/A/B/foo bar.jpg");}
|
||||
@import url('http://cnd.com/A/B/foo bar.css');
|
||||
@import "http://cnd.com/A/B/foo bar.css";
|
||||
|
@@ -12,3 +12,6 @@ foo {background:url('//cnd.com/A/B/bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(foo:bar);} /* scheme, should not alter */
|
||||
foo {background:url("//cnd.com/A/B/foo bar.jpg");}
|
||||
@import url('//cnd.com/A/B/foo bar.css');
|
||||
@import "//cnd.com/A/B/foo bar.css";
|
||||
|
@@ -12,3 +12,6 @@ foo {background:url('bar/foo.png')}
|
||||
foo {background:url('http://foo.com/css/foo.css');} /* scheme, should not alter */
|
||||
foo {background:url("//foo.com/css/foo.css");} /* protocol relative, should not alter */
|
||||
foo {background:url(foo:bar);} /* scheme, should not alter */
|
||||
foo {background:url("foo bar.jpg");}
|
||||
@import url('foo bar.css');
|
||||
@import "foo bar.css";
|
||||
|
@@ -9,7 +9,7 @@ function test_Minify_Cache_File()
|
||||
|
||||
$cache = new Minify_Cache_File();
|
||||
|
||||
echo "NOTE: Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
|
||||
echo " Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
|
@@ -8,14 +8,14 @@ function test_Minify_Cache_Memcache()
|
||||
|
||||
if (! function_exists('memcache_set')) {
|
||||
if ($thisFileActive) {
|
||||
echo "NOTE: {$prefix}PHP lacks memcache support\n";
|
||||
echo " {$prefix}To test this component, install memcache in PHP\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
$mc = new Memcache;
|
||||
if (! @$mc->connect('localhost', 11211)) {
|
||||
if ($thisFileActive) {
|
||||
echo "NOTE: {$prefix}Could not connect to localhost:11211\n";
|
||||
echo " {$prefix}Memcache server not found on localhost:11211\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
31
min_unit_tests/test_Minify_Cache_WinCache.php
Normal file
31
min_unit_tests/test_Minify_Cache_WinCache.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once '_inc.php';
|
||||
|
||||
function test_Minify_Cache_WinCache()
|
||||
{
|
||||
$prefix = 'Minify_Cache_WinCache : ';
|
||||
if (! function_exists('wincache_ucache_info')) {
|
||||
return;
|
||||
}
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache';
|
||||
|
||||
$cache = new Minify_Cache_WinCache();
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
ob_start();
|
||||
$cache->display($id);
|
||||
$displayed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
assertTrue($data === $displayed, $prefix . 'display');
|
||||
|
||||
assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
|
||||
}
|
||||
|
||||
test_Minify_Cache_WinCache();
|
75
min_unit_tests/test_Minify_ClosureCompiler.php
Normal file
75
min_unit_tests/test_Minify_ClosureCompiler.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
require_once '_inc.php';
|
||||
|
||||
function test_Minify_ClosureCompiler()
|
||||
{
|
||||
global $thisDir;
|
||||
Minify_ClosureCompiler::$isDebug = true;
|
||||
|
||||
|
||||
// --- Test minification w/o setting the necessary settings ---
|
||||
try {
|
||||
Minify_ClosureCompiler::minify('');
|
||||
} catch (Exception $e) {
|
||||
$exc = $e;
|
||||
}
|
||||
$passed = assertTrue(
|
||||
$exc instanceof Minify_ClosureCompiler_Exception
|
||||
, 'Minify_ClosureCompiler : Throws Minify_ClosureCompiler_Exception');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Message: " . var_export($exc->getMessage(), 1) . "\n\n\n";
|
||||
}
|
||||
|
||||
$compiler_jar_path = __DIR__ . DIRECTORY_SEPARATOR . 'compiler.jar';
|
||||
if (is_file($compiler_jar_path)) {
|
||||
|
||||
// set minimum necessary settings
|
||||
Minify_ClosureCompiler::$jarFile = $compiler_jar_path;
|
||||
Minify_ClosureCompiler::$tempDir = sys_get_temp_dir();
|
||||
|
||||
|
||||
// --- Test minification with the minimum necessary settings ---
|
||||
|
||||
$src = "
|
||||
(function (window, undefined){
|
||||
function addOne(input) {
|
||||
return 1 + input;
|
||||
}
|
||||
window.addOne = addOne;
|
||||
window.undefined = undefined;
|
||||
})(window);
|
||||
";
|
||||
$minExpected = "(function(a,b){a.addOne=function(a){return 1+a};a.undefined=b})(window);";
|
||||
$minOutput = Minify_ClosureCompiler::minify($src);
|
||||
$passed = assertTrue($minExpected == $minOutput, 'Minify_ClosureCompiler : minimum necessary settings');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
|
||||
|
||||
// --- Test minification with advanced compilation level ---
|
||||
|
||||
$src = "function unused() {};";
|
||||
$minExpected = '';
|
||||
$minOutput = Minify_ClosureCompiler::minify($src, array(
|
||||
Minify_ClosureCompiler::OPTION_COMPILATION_LEVEL => 'ADVANCED_OPTIMIZATIONS'
|
||||
));
|
||||
$passed = assertTrue($minExpected == $minOutput, 'Minify_ClosureCompiler : advanced optimizations');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
|
||||
} else {
|
||||
echo " Minify_ClosureCompiler : To test more functionality, download a compiler.jar from\n";
|
||||
echo " https://code.google.com/p/closure-compiler/wiki/BinaryDownloads,\n";
|
||||
echo " put it under '${compiler_jar_path}',\n";
|
||||
echo " and make it readable by your webserver\n";
|
||||
}
|
||||
}
|
||||
|
||||
test_Minify_ClosureCompiler();
|
@@ -17,7 +17,7 @@ function test_Minify_JS_ClosureCompiler()
|
||||
$minExpected = "(function(a,b){a.addOne=function(a){return 1+a};a.undefined=b})(window);";
|
||||
$minOutput = Minify_JS_ClosureCompiler::minify($src);
|
||||
if (false !== strpos($minOutput, 'Error(22): Too many compiles')) {
|
||||
echo "!NOTE: Too many recent calls to Closure Compiler API to test.\n";
|
||||
echo "!---: Minify_JS_ClosureCompiler : Too many recent calls to Closure Compiler API to test.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,20 @@
|
||||
<?php
|
||||
require_once '_inc.php';
|
||||
|
||||
// customize this as needed
|
||||
define('MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE', '/usr/share/java/yuicompressor.jar');
|
||||
|
||||
|
||||
|
||||
function test_Minify_YuiCSS()
|
||||
{
|
||||
// XXX this may need customizing
|
||||
Minify_YUICompressor::$jarFile = '/usr/share/java/yuicompressor.jar';
|
||||
if (!is_file(MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE)) {
|
||||
echo " Minify_YUICompressor : To test this, install the .jar file and customize the constant in:\n";
|
||||
echo " " . __FILE__ . "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
Minify_YUICompressor::$jarFile = MINIFY_TESTS_YUICOMPRESSOR_JAR_FILE;
|
||||
Minify_YUICompressor::$tempDir = sys_get_temp_dir();
|
||||
|
||||
$src = "/* stack overflow test */
|
||||
@@ -20,9 +30,9 @@ function test_Minify_YuiCSS()
|
||||
// unfortunately error output is not caught from yui, so have to guess
|
||||
try {
|
||||
$minOutput = Minify_YUICompressor::minifyCss($src);
|
||||
assertTrue(false, "Expected exception Not thrown");
|
||||
echo " Minify_YUICompressor : Correctly handles input which caused stack overflow in 2.4.6\n";
|
||||
} catch (Exception $e) {
|
||||
assertTrue($e->getMessage() == 'Minify_YUICompressor : YUI compressor execution failed.', 'got expected Exception');
|
||||
assertTrue($e->getMessage() == 'Minify_YUICompressor : YUI compressor execution failed.', 'Minify_YUICompressor : got expected Exception');
|
||||
}
|
||||
|
||||
try {
|
||||
|
@@ -6,9 +6,11 @@ require 'test_Minify_HTML_Helper.php';
|
||||
require 'test_Minify_Cache_APC.php';
|
||||
require 'test_Minify_Cache_File.php';
|
||||
require 'test_Minify_Cache_Memcache.php';
|
||||
require 'test_Minify_Cache_WinCache.php';
|
||||
require 'test_Minify_Cache_ZendPlatform.php';
|
||||
require 'test_Minify_CSS.php';
|
||||
require 'test_Minify_CSS_UriRewriter.php';
|
||||
require 'test_Minify_ClosureCompiler.php';
|
||||
require 'test_Minify_JS_ClosureCompiler.php';
|
||||
require 'test_Minify_YuiCSS.php';
|
||||
require 'test_Minify_CommentPreserver.php';
|
||||
|
@@ -43,11 +43,11 @@ function test_environment()
|
||||
. "cannot modify this, consider setting \$min_documentRoot in config.php\n\n";
|
||||
}
|
||||
if (isset($_SERVER['SUBDOMAIN_DOCUMENT_ROOT'])) {
|
||||
echo "\n!NOTE: environment : \$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. "
|
||||
echo "\n environment : \$_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] is set. "
|
||||
. "You may need to set \$min_documentRoot to this in config.php\n";
|
||||
}
|
||||
if (realpath(__FILE__) !== realpath($_SERVER['DOCUMENT_ROOT'] . '/min_unit_tests/test_environment.php')) {
|
||||
echo "!NOTE: environment : /min_unit_tests/ is not directly inside DOCUMENT_ROOT\n";
|
||||
echo " environment : /min_unit_tests/ is not directly inside DOCUMENT_ROOT\n";
|
||||
}
|
||||
|
||||
$thisUrl = 'http://'
|
||||
@@ -59,11 +59,11 @@ function test_environment()
|
||||
$oc = @file_get_contents($thisUrl . '?getOutputCompression=1');
|
||||
|
||||
if (false === $oc || ! preg_match('/^[01]$/', $oc)) {
|
||||
echo "!WARN: environment : Local HTTP request failed. Testing cannot continue.\n";
|
||||
echo "!---: environment : Local HTTP request failed. Testing cannot continue.\n";
|
||||
return;
|
||||
}
|
||||
if ('1' === $oc) {
|
||||
echo "!WARN: environment : zlib.output_compression is enabled in php.ini"
|
||||
echo "!---: environment : zlib.output_compression is enabled in php.ini"
|
||||
. " or .htaccess.\n";
|
||||
}
|
||||
|
||||
@@ -88,9 +88,9 @@ function test_environment()
|
||||
if (! $passed) {
|
||||
$testFake = _test_environment_getHello($thisUrl . '?hello=faketype');
|
||||
if ($testFake['length'] == 6) {
|
||||
echo "!NOTE: environment : Server does not auto-encode arbitrary types. This\n"
|
||||
. " may indicate that the auto-encoding is caused by Apache's \n"
|
||||
. " AddOutputFilterByType.";
|
||||
echo " environment : Server does not auto-encode arbitrary types. This\n"
|
||||
. " may indicate that the auto-encoding is caused by Apache's\n"
|
||||
. " AddOutputFilterByType.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user