1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-21 13:21:59 +02:00

Merge pull request #126 from glensc/autoloader

rework classloader
This commit is contained in:
Elan Ruusamäe
2014-11-17 23:23:11 +02:00
23 changed files with 68 additions and 67 deletions

7
.gitignore vendored
View File

@@ -1,7 +1,6 @@
# /
/test
/docs
.idea/
/.idea/
.DS_Store
vendor
/vendor/
!/vendor/bootstrap.php

View File

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

View File

@@ -22,11 +22,9 @@ if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
}
}
require dirname(__FILE__) . '/../../vendor/bootstrap.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__) . '/../../vendor/bootstrap.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'];
@@ -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');

View File

@@ -7,6 +7,8 @@
* @package Minify
*/
require dirname(__FILE__). '/../vendor/bootstrap.php';
define('MINIFY_MIN_DIR', dirname(__FILE__));
// set config path defaults
@@ -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,10 +10,7 @@
* @package Minify
*/
if (! class_exists('Minify_Loader', false)) {
require dirname(__FILE__) . '/lib/Minify/Loader.php';
Minify_Loader::register();
}
require dirname(__FILE__) . '/../vendor/bootstrap.php';
/*
* Get an HTML-escaped Minify URI for a group or set of files. By default, URIs

View File

@@ -1,10 +1,7 @@
#!/usr/bin/env php
<?php
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "$pathToLib/Minify/Loader.php";
Minify_Loader::register();
require dirname(dirname(__DIR__)) . '/vendor/bootstrap.php';
$cli = new MrClay\Cli;

View File

@@ -1,10 +1,7 @@
#!/usr/bin/php
<?php
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib';
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
require dirname(dirname(__DIR__)) . '/vendor/bootstrap.php';
$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__) . '/../../vendor/bootstrap.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__) . '/../../vendor/bootstrap.php';
function getPost($key) {
if (! isset($_POST[$key])) {
return null;

View File

@@ -1,4 +1,7 @@
<?php
require dirname(__FILE__) . '/../../vendor/bootstrap.php';
header('Content-Type: text/html;charset=utf-8');
function h($str) { return htmlspecialchars($str, ENT_QUOTES); }

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__) . '/../../vendor/bootstrap.php';
// emulate regularly updating document
$every = 20;

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__) . '/../../../vendor/bootstrap.php';
// generate content first (not ideal)
// emulate regularly updating document

View File

@@ -1,13 +1,11 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib'));
require 'HTTP/ConditionalGet.php';
require dirname(__FILE__) . '/../../../vendor/bootstrap.php';
// emulate regularly updating document
$every = 20;
$lastModified = round(time()/$every)*$every - $every;
require 'HTTP/Encoder.php';
list($enc,) = HTTP_Encoder::getAcceptedEncoding();
$cg = new HTTP_ConditionalGet(array(

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__) . '/../../vendor/bootstrap.php';
// far expires
$cg = new HTTP_ConditionalGet(array(

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__) . '/../../vendor/bootstrap.php';
// emulate regularly updating document
$every = 20;

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__) . '/../../vendor/bootstrap.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__) . '/../vendor/bootstrap.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

19
vendor/bootstrap.php vendored Normal file
View File

@@ -0,0 +1,19 @@
<?php
/**
* Sets up autoloader for Minify
*
* @package Minify
*/
$includeIfExists = function($file) {
return file_exists($file) ? include $file : false;
};
if (!$includeIfExists(__DIR__.'/autoload.php')) {
echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
'php composer.phar install'.PHP_EOL;
exit(1);
}
unset($includeIfExists);