From 96da497e9c2f0e722164b56aac136ebfd9862a72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?=
Date: Sun, 12 Oct 2014 16:27:43 +0300
Subject: [PATCH 1/5] rework classloader
- make it available in config
- always use classloader, no manual require
- compatible for future composer alternative
---
min/builder/index.php | 4 +---
min/builder/ocCheck.php | 3 ++-
min/config.php | 2 +-
min/index.php | 5 ++---
min/lib/Minify/Loader.php | 16 +++++++++++++++-
min/lib/Minify/Packer.php | 8 --------
min/utils.php | 3 +--
min_extras/cli/minify.php | 1 -
min_extras/cli/rewrite-uris.php | 1 -
min_extras/config.php | 3 ---
min_extras/tools/minifyTextarea.php | 2 ++
min_extras/tools/minifyUrl.php | 2 ++
min_extras/tools/testRewriteUri.php | 5 ++++-
min_unit_tests/HTTP_ConditionalGet/index.php | 5 ++---
min_unit_tests/HTTP_Encoder/index.php | 5 +----
min_unit_tests/_inc.php | 6 ++----
16 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/min/builder/index.php b/min/builder/index.php
index 35e10a9..b033933 100644
--- a/min/builder/index.php
+++ b/min/builder/index.php
@@ -22,11 +22,9 @@ if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
}
}
+require dirname(__FILE__) . '/../lib/Minify/Loader.php';
require dirname(__FILE__) . '/../config.php';
-require "$min_libPath/Minify/Loader.php";
-Minify_Loader::register();
-
if (! $min_enableBuilder) {
header('Content-Type: text/plain');
die('This application is not enabled. See http://code.google.com/p/minify/wiki/BuilderApp');
diff --git a/min/builder/ocCheck.php b/min/builder/ocCheck.php
index 5c40e74..2aa5abf 100644
--- a/min/builder/ocCheck.php
+++ b/min/builder/ocCheck.php
@@ -5,6 +5,8 @@
* @package Minify
*/
+require dirname(__FILE__) . '/../lib/Minify/Loader.php';
+
$_oc = ini_get('zlib.output_compression');
// allow access only if builder is enabled
@@ -20,7 +22,6 @@ if (isset($_GET['hello'])) {
// try to prevent double encoding (may not have an effect)
ini_set('zlib.output_compression', '0');
- require $min_libPath . '/HTTP/Encoder.php';
HTTP_Encoder::$encodeToIe6 = true; // just in case
$he = new HTTP_Encoder(array(
'content' => 'World!'
diff --git a/min/config.php b/min/config.php
index ee757e1..b198b0f 100644
--- a/min/config.php
+++ b/min/config.php
@@ -57,7 +57,6 @@ $min_allowDebugFlag = false;
* To use APC/Memcache/ZendPlatform for cache storage, require the class and
* set $min_cachePath to an instance. Example below:
*/
-//require dirname(__FILE__) . '/lib/Minify/Cache/APC.php';
//$min_cachePath = new Minify_Cache_APC();
@@ -72,6 +71,7 @@ $min_allowDebugFlag = false;
* second line. The third line might work on some Apache servers.
*/
$min_documentRoot = '';
+//$min_documentRoot = dirname(dirname(dirname(__FILE__)));
//$min_documentRoot = substr(__FILE__, 0, -15);
//$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'];
diff --git a/min/index.php b/min/index.php
index f23d508..7f78a7c 100644
--- a/min/index.php
+++ b/min/index.php
@@ -9,6 +9,8 @@
define('MINIFY_MIN_DIR', dirname(__FILE__));
+require MINIFY_MIN_DIR . '/lib/Minify/Loader.php';
+
// set config path defaults
$min_configPaths = array(
'base' => MINIFY_MIN_DIR . '/config.php',
@@ -28,9 +30,6 @@ if (isset($_GET['test'])) {
include $min_configPaths['test'];
}
-require "$min_libPath/Minify/Loader.php";
-Minify_Loader::register();
-
// use an environment object to encapsulate all input
$server = $_SERVER;
if ($min_documentRoot) {
diff --git a/min/lib/Minify/Loader.php b/min/lib/Minify/Loader.php
index 0a225c0..591528f 100644
--- a/min/lib/Minify/Loader.php
+++ b/min/lib/Minify/Loader.php
@@ -17,12 +17,26 @@ class Minify_Loader {
$file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php';
if (is_readable($file)) {
require $file;
+ return;
}
+
+ $map = array(
+ 'JavascriptPacker' => 'class.JavaScriptPacker.php',
+ );
+
+ if (!isset($map[$class])) {
+ return;
+ }
+
+ @include $map[$class];
}
- static public function register()
+ public static function register()
{
$inst = new self();
spl_autoload_register(array($inst, 'loadClass'));
+ return $inst;
}
}
+
+return Minify_Loader::register();
diff --git a/min/lib/Minify/Packer.php b/min/lib/Minify/Packer.php
index 949c3ee..1826990 100644
--- a/min/lib/Minify/Packer.php
+++ b/min/lib/Minify/Packer.php
@@ -14,14 +14,6 @@
* @package Minify
*/
-if (false === (@include 'class.JavaScriptPacker.php')) {
- trigger_error(
- 'The script "class.JavaScriptPacker.php" is required. Please see: http:'
- .'//code.google.com/p/minify/source/browse/trunk/min/lib/Minify/Packer.php'
- ,E_USER_ERROR
- );
-}
-
/**
* Minify Javascript using Dean Edward's Packer
*
diff --git a/min/utils.php b/min/utils.php
index 7cf930a..286568f 100644
--- a/min/utils.php
+++ b/min/utils.php
@@ -10,9 +10,8 @@
* @package Minify
*/
-if (! class_exists('Minify_Loader', false)) {
+if (!class_exists('Minify_Loader', false)) {
require dirname(__FILE__) . '/lib/Minify/Loader.php';
- Minify_Loader::register();
}
/*
diff --git a/min_extras/cli/minify.php b/min_extras/cli/minify.php
index e0c4b15..6482fdb 100755
--- a/min_extras/cli/minify.php
+++ b/min_extras/cli/minify.php
@@ -4,7 +4,6 @@
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "$pathToLib/Minify/Loader.php";
-Minify_Loader::register();
$cli = new MrClay\Cli;
diff --git a/min_extras/cli/rewrite-uris.php b/min_extras/cli/rewrite-uris.php
index e0cbfa5..5f51340 100755
--- a/min_extras/cli/rewrite-uris.php
+++ b/min_extras/cli/rewrite-uris.php
@@ -4,7 +4,6 @@
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "$min_libPath/Minify/Loader.php";
-Minify_Loader::register();
$cli = new MrClay\Cli;
diff --git a/min_extras/config.php b/min_extras/config.php
index b44bceb..3874313 100644
--- a/min_extras/config.php
+++ b/min_extras/config.php
@@ -4,9 +4,6 @@
require dirname(__FILE__) . '/../min/config.php';
-require "$min_libPath/Minify/Loader.php";
-Minify_Loader::register();
-
$minifyCachePath = isset($min_cachePath)
? $min_cachePath
: '';
diff --git a/min_extras/tools/minifyTextarea.php b/min_extras/tools/minifyTextarea.php
index 8199fd6..274a61e 100644
--- a/min_extras/tools/minifyTextarea.php
+++ b/min_extras/tools/minifyTextarea.php
@@ -1,5 +1,7 @@
-
\ No newline at end of file
+
diff --git a/min_unit_tests/HTTP_ConditionalGet/index.php b/min_unit_tests/HTTP_ConditionalGet/index.php
index 0e4192e..d2dad82 100644
--- a/min_unit_tests/HTTP_ConditionalGet/index.php
+++ b/min_unit_tests/HTTP_ConditionalGet/index.php
@@ -1,7 +1,6 @@
$title
,'explain' => $explain
)));
-
+
diff --git a/min_unit_tests/HTTP_Encoder/index.php b/min_unit_tests/HTTP_Encoder/index.php
index c9a391d..663750c 100644
--- a/min_unit_tests/HTTP_Encoder/index.php
+++ b/min_unit_tests/HTTP_Encoder/index.php
@@ -1,8 +1,7 @@
encode();
$he->sendAll();
-
-?>
\ No newline at end of file
diff --git a/min_unit_tests/_inc.php b/min_unit_tests/_inc.php
index 197ed95..2e63304 100644
--- a/min_unit_tests/_inc.php
+++ b/min_unit_tests/_inc.php
@@ -1,10 +1,8 @@
Date: Sun, 12 Oct 2014 17:15:49 +0300
Subject: [PATCH 2/5] use autoloader in tests
---
min_unit_tests/HTTP_ConditionalGet/2.php | 3 +--
min_unit_tests/HTTP_ConditionalGet/3.php | 5 ++---
min_unit_tests/HTTP_ConditionalGet/4.php | 4 +---
min_unit_tests/HTTP_ConditionalGet/5.php | 3 +--
4 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/min_unit_tests/HTTP_ConditionalGet/2.php b/min_unit_tests/HTTP_ConditionalGet/2.php
index 9b66f24..cc73957 100644
--- a/min_unit_tests/HTTP_ConditionalGet/2.php
+++ b/min_unit_tests/HTTP_ConditionalGet/2.php
@@ -1,7 +1,6 @@
setContentLength(strlen($content));
$cg->sendHeaders();
send_slowly($content);
-
+
diff --git a/min_unit_tests/HTTP_ConditionalGet/4.php b/min_unit_tests/HTTP_ConditionalGet/4.php
index 4b77d20..aec6ead 100644
--- a/min_unit_tests/HTTP_ConditionalGet/4.php
+++ b/min_unit_tests/HTTP_ConditionalGet/4.php
@@ -1,13 +1,11 @@
Date: Sun, 12 Oct 2014 17:21:21 +0300
Subject: [PATCH 3/5] get rid of $min_libPath
---
min/config.php | 7 -------
min_extras/cli/rewrite-uris.php | 4 +---
2 files changed, 1 insertion(+), 10 deletions(-)
diff --git a/min/config.php b/min/config.php
index b198b0f..4d9f355 100644
--- a/min/config.php
+++ b/min/config.php
@@ -180,12 +180,5 @@ $min_symlinks = array();
$min_uploaderHoursBehind = 0;
-/**
- * Path to Minify's lib folder. If you happen to move it, change
- * this accordingly.
- */
-$min_libPath = dirname(__FILE__) . '/lib';
-
-
// try to disable output_compression (may not have an effect)
ini_set('zlib.output_compression', '0');
diff --git a/min_extras/cli/rewrite-uris.php b/min_extras/cli/rewrite-uris.php
index 5f51340..a0577f4 100755
--- a/min_extras/cli/rewrite-uris.php
+++ b/min_extras/cli/rewrite-uris.php
@@ -1,9 +1,7 @@
#!/usr/bin/php
Date: Sun, 12 Oct 2014 18:30:31 +0300
Subject: [PATCH 4/5] add firephp to composer
---
composer.json | 2 ++
1 file changed, 2 insertions(+)
diff --git a/composer.json b/composer.json
index 3bfb17d..7df82f2 100644
--- a/composer.json
+++ b/composer.json
@@ -24,11 +24,13 @@
"ext-pcre": "*"
},
"require-dev": {
+ "firephp/firephp-core": "~0.4.0",
"leafo/lessphp": "~0.4.0",
"meenie/javascript-packer": "~1.1",
"tubalmartin/cssmin": "~2.4.8"
},
"suggest": {
+ "firephp/firephp-core": "FirePHP debug output",
"leafo/lessphp": "LESS support",
"meenie/javascript-packer": "Keep track of the Packer PHP port using Composer",
"tubalmartin/cssmin": "Support minify with CSSMin (YUI PHP port)"
From 0e9e1237c62067074cd13e5f3beea1dff2a4283a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?=
Date: Wed, 15 Oct 2014 23:51:13 +0300
Subject: [PATCH 5/5] make composer dependency required
NOTE: this changes required minimum PHP version to 5.3.3
---
.gitignore | 11 +++++------
min/builder/index.php | 2 +-
min/builder/ocCheck.php | 2 +-
min/index.php | 4 ++--
min/utils.php | 4 +---
min_extras/cli/minify.php | 4 +---
min_extras/cli/rewrite-uris.php | 2 +-
min_extras/tools/minifyTextarea.php | 2 +-
min_extras/tools/minifyUrl.php | 2 +-
min_extras/tools/testRewriteUri.php | 2 +-
min_unit_tests/HTTP_ConditionalGet/2.php | 2 +-
min_unit_tests/HTTP_ConditionalGet/3.php | 2 +-
min_unit_tests/HTTP_ConditionalGet/4.php | 2 +-
min_unit_tests/HTTP_ConditionalGet/5.php | 2 +-
min_unit_tests/HTTP_ConditionalGet/index.php | 2 +-
min_unit_tests/HTTP_Encoder/index.php | 2 +-
min_unit_tests/_inc.php | 2 +-
vendor/bootstrap.php | 19 +++++++++++++++++++
18 files changed, 41 insertions(+), 27 deletions(-)
create mode 100644 vendor/bootstrap.php
diff --git a/.gitignore b/.gitignore
index f4558c7..427148e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,6 @@
-
-# /
-/test
-/docs
-.idea/
+/test
+/docs
+/.idea/
.DS_Store
-vendor
+/vendor/
+!/vendor/bootstrap.php
diff --git a/min/builder/index.php b/min/builder/index.php
index b033933..de19dd4 100644
--- a/min/builder/index.php
+++ b/min/builder/index.php
@@ -22,7 +22,7 @@ if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
}
}
-require dirname(__FILE__) . '/../lib/Minify/Loader.php';
+require dirname(__FILE__) . '/../../vendor/bootstrap.php';
require dirname(__FILE__) . '/../config.php';
if (! $min_enableBuilder) {
diff --git a/min/builder/ocCheck.php b/min/builder/ocCheck.php
index 2aa5abf..4af8525 100644
--- a/min/builder/ocCheck.php
+++ b/min/builder/ocCheck.php
@@ -5,7 +5,7 @@
* @package Minify
*/
-require dirname(__FILE__) . '/../lib/Minify/Loader.php';
+require dirname(__FILE__) . '/../../vendor/bootstrap.php';
$_oc = ini_get('zlib.output_compression');
diff --git a/min/index.php b/min/index.php
index 7f78a7c..e8c36e7 100644
--- a/min/index.php
+++ b/min/index.php
@@ -7,9 +7,9 @@
* @package Minify
*/
-define('MINIFY_MIN_DIR', dirname(__FILE__));
+require dirname(__FILE__). '/../vendor/bootstrap.php';
-require MINIFY_MIN_DIR . '/lib/Minify/Loader.php';
+define('MINIFY_MIN_DIR', dirname(__FILE__));
// set config path defaults
$min_configPaths = array(
diff --git a/min/utils.php b/min/utils.php
index 286568f..80c89b1 100644
--- a/min/utils.php
+++ b/min/utils.php
@@ -10,9 +10,7 @@
* @package Minify
*/
-if (!class_exists('Minify_Loader', false)) {
- require dirname(__FILE__) . '/lib/Minify/Loader.php';
-}
+require dirname(__FILE__) . '/../vendor/bootstrap.php';
/*
* Get an HTML-escaped Minify URI for a group or set of files. By default, URIs
diff --git a/min_extras/cli/minify.php b/min_extras/cli/minify.php
index 6482fdb..e3df308 100755
--- a/min_extras/cli/minify.php
+++ b/min_extras/cli/minify.php
@@ -1,9 +1,7 @@
#!/usr/bin/env php