1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-12 09:05:08 +02:00

rework classloader

- make it available in config
- always use classloader, no manual require
- compatible for future composer alternative
This commit is contained in:
Elan Ruusamäe
2014-10-12 16:27:43 +03:00
parent 4b495f6ae0
commit 96da497e9c
16 changed files with 35 additions and 36 deletions

View File

@@ -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');

View File

@@ -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!'

View File

@@ -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'];

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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
*

View File

@@ -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();
}
/*

View File

@@ -4,7 +4,6 @@
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "$pathToLib/Minify/Loader.php";
Minify_Loader::register();
$cli = new MrClay\Cli;

View File

@@ -4,7 +4,6 @@
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
$cli = new MrClay\Cli;

View File

@@ -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
: '';

View File

@@ -1,5 +1,7 @@
<?php
require dirname(__FILE__) . '/../../min/lib/Minify/Loader.php';
function getPost($key) {
return get_magic_quotes_gpc()
? stripslashes($_POST[$key])

View File

@@ -3,6 +3,8 @@
* Fetch and minify a URL (auto-detect HTML/JS/CSS)
*/
require dirname(__FILE__) . '/../../min/lib/Minify/Loader.php';
function getPost($key) {
if (! isset($_POST[$key])) {
return null;

View File

@@ -1,4 +1,7 @@
<?php
require dirname(__FILE__) . '/../../min/lib/Minify/Loader.php';
header('Content-Type: text/html;charset=utf-8');
function h($str) { return htmlspecialchars($str, ENT_QUOTES); }
@@ -55,4 +58,4 @@ if (isset($_POST['css'])) {
<p><label>input CSS: <textarea name="css" cols="80" rows="5"><?php echo h(getPost('css', $defaultCss)); ?></textarea></label></p>
<p><input type="submit" value="rewrite()" /></p>
</form>
<?php echo $out; ?>
<?php echo $out; ?>

View File

@@ -1,7 +1,6 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib'));
require 'HTTP/ConditionalGet.php';
require dirname(__FILE__) . '/../../min/lib/Minify/Loader.php';
// emulate regularly updating document
$every = 20;
@@ -33,4 +32,4 @@ echo send_slowly(get_content(array(
'title' => $title
,'explain' => $explain
)));

View File

@@ -1,8 +1,7 @@
<?php
ini_set('display_errors', 'on');
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib'));
require 'HTTP/Encoder.php';
require dirname(__FILE__) . '/../../min/lib/Minify/Loader.php';
if (!isset($_GET['test'])) {
$type = 'text/html';
@@ -56,5 +55,3 @@ $he = new HTTP_Encoder(array(
));
$he->encode();
$he->sendAll();
?>

View File

@@ -1,10 +1,8 @@
<?php
require dirname(__FILE__) . '/../min/lib/Minify/Loader.php';
require dirname(__FILE__) . '/../min/config.php';
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
// set cache path and doc root if configured
$minifyCachePath = isset($min_cachePath)
? $min_cachePath
@@ -59,4 +57,4 @@ function countBytes($str)
: strlen($str);
}
ob_start();
ob_start();