1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-22 05:33:14 +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 /test
/docs /docs
.idea/ /.idea/
.DS_Store .DS_Store
vendor /vendor/
!/vendor/bootstrap.php

View File

@@ -24,11 +24,13 @@
"ext-pcre": "*" "ext-pcre": "*"
}, },
"require-dev": { "require-dev": {
"firephp/firephp-core": "~0.4.0",
"leafo/lessphp": "~0.4.0", "leafo/lessphp": "~0.4.0",
"meenie/javascript-packer": "~1.1", "meenie/javascript-packer": "~1.1",
"tubalmartin/cssmin": "~2.4.8" "tubalmartin/cssmin": "~2.4.8"
}, },
"suggest": { "suggest": {
"firephp/firephp-core": "FirePHP debug output",
"leafo/lessphp": "LESS support", "leafo/lessphp": "LESS support",
"meenie/javascript-packer": "Keep track of the Packer PHP port using Composer", "meenie/javascript-packer": "Keep track of the Packer PHP port using Composer",
"tubalmartin/cssmin": "Support minify with CSSMin (YUI PHP port)" "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 dirname(__FILE__) . '/../config.php';
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
if (! $min_enableBuilder) { if (! $min_enableBuilder) {
header('Content-Type: text/plain'); header('Content-Type: text/plain');
die('This application is not enabled. See http://code.google.com/p/minify/wiki/BuilderApp'); die('This application is not enabled. See http://code.google.com/p/minify/wiki/BuilderApp');

View File

@@ -5,6 +5,8 @@
* @package Minify * @package Minify
*/ */
require dirname(__FILE__) . '/../../vendor/bootstrap.php';
$_oc = ini_get('zlib.output_compression'); $_oc = ini_get('zlib.output_compression');
// allow access only if builder is enabled // 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) // try to prevent double encoding (may not have an effect)
ini_set('zlib.output_compression', '0'); ini_set('zlib.output_compression', '0');
require $min_libPath . '/HTTP/Encoder.php';
HTTP_Encoder::$encodeToIe6 = true; // just in case HTTP_Encoder::$encodeToIe6 = true; // just in case
$he = new HTTP_Encoder(array( $he = new HTTP_Encoder(array(
'content' => 'World!' 'content' => 'World!'

View File

@@ -57,7 +57,6 @@ $min_allowDebugFlag = false;
* To use APC/Memcache/ZendPlatform for cache storage, require the class and * To use APC/Memcache/ZendPlatform for cache storage, require the class and
* set $min_cachePath to an instance. Example below: * set $min_cachePath to an instance. Example below:
*/ */
//require dirname(__FILE__) . '/lib/Minify/Cache/APC.php';
//$min_cachePath = new Minify_Cache_APC(); //$min_cachePath = new Minify_Cache_APC();
@@ -72,6 +71,7 @@ $min_allowDebugFlag = false;
* second line. The third line might work on some Apache servers. * second line. The third line might work on some Apache servers.
*/ */
$min_documentRoot = ''; $min_documentRoot = '';
//$min_documentRoot = dirname(dirname(dirname(__FILE__)));
//$min_documentRoot = substr(__FILE__, 0, -15); //$min_documentRoot = substr(__FILE__, 0, -15);
//$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT']; //$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'];
@@ -180,12 +180,5 @@ $min_symlinks = array();
$min_uploaderHoursBehind = 0; $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) // try to disable output_compression (may not have an effect)
ini_set('zlib.output_compression', '0'); ini_set('zlib.output_compression', '0');

View File

@@ -7,6 +7,8 @@
* @package Minify * @package Minify
*/ */
require dirname(__FILE__). '/../vendor/bootstrap.php';
define('MINIFY_MIN_DIR', dirname(__FILE__)); define('MINIFY_MIN_DIR', dirname(__FILE__));
// set config path defaults // set config path defaults
@@ -28,9 +30,6 @@ if (isset($_GET['test'])) {
include $min_configPaths['test']; include $min_configPaths['test'];
} }
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
// use an environment object to encapsulate all input // use an environment object to encapsulate all input
$server = $_SERVER; $server = $_SERVER;
if ($min_documentRoot) { if ($min_documentRoot) {

View File

@@ -17,12 +17,26 @@ class Minify_Loader {
$file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php'; $file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php';
if (is_readable($file)) { if (is_readable($file)) {
require $file; require $file;
} return;
} }
static public function register() $map = array(
'JavascriptPacker' => 'class.JavaScriptPacker.php',
);
if (!isset($map[$class])) {
return;
}
@include $map[$class];
}
public static function register()
{ {
$inst = new self(); $inst = new self();
spl_autoload_register(array($inst, 'loadClass')); spl_autoload_register(array($inst, 'loadClass'));
return $inst;
} }
} }
return Minify_Loader::register();

View File

@@ -14,14 +14,6 @@
* @package Minify * @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 * Minify Javascript using Dean Edward's Packer
* *

View File

@@ -10,10 +10,7 @@
* @package Minify * @package Minify
*/ */
if (! class_exists('Minify_Loader', false)) { require dirname(__FILE__) . '/../vendor/bootstrap.php';
require dirname(__FILE__) . '/lib/Minify/Loader.php';
Minify_Loader::register();
}
/* /*
* Get an HTML-escaped Minify URI for a group or set of files. By default, URIs * 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 #!/usr/bin/env php
<?php <?php
$pathToLib = dirname(dirname(__DIR__)) . '/min/lib'; require dirname(dirname(__DIR__)) . '/vendor/bootstrap.php';
require "$pathToLib/Minify/Loader.php";
Minify_Loader::register();
$cli = new MrClay\Cli; $cli = new MrClay\Cli;

View File

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

View File

@@ -4,9 +4,6 @@
require dirname(__FILE__) . '/../min/config.php'; require dirname(__FILE__) . '/../min/config.php';
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
$minifyCachePath = isset($min_cachePath) $minifyCachePath = isset($min_cachePath)
? $min_cachePath ? $min_cachePath
: ''; : '';

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,6 @@
<?php <?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib')); require dirname(__FILE__) . '/../../vendor/bootstrap.php';
require 'HTTP/ConditionalGet.php';
// emulate regularly updating document // emulate regularly updating document
$every = 20; $every = 20;

View File

@@ -1,7 +1,6 @@
<?php <?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib')); require dirname(__FILE__) . '/../../../vendor/bootstrap.php';
require 'HTTP/ConditionalGet.php';
// generate content first (not ideal) // generate content first (not ideal)
// emulate regularly updating document // emulate regularly updating document

View File

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

View File

@@ -1,7 +1,6 @@
<?php <?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib')); require dirname(__FILE__) . '/../../vendor/bootstrap.php';
require 'HTTP/ConditionalGet.php';
// far expires // far expires
$cg = new HTTP_ConditionalGet(array( $cg = new HTTP_ConditionalGet(array(

View File

@@ -1,7 +1,6 @@
<?php <?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../min/lib')); require dirname(__FILE__) . '/../../vendor/bootstrap.php';
require 'HTTP/ConditionalGet.php';
// emulate regularly updating document // emulate regularly updating document
$every = 20; $every = 20;

View File

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

View File

@@ -1,10 +1,8 @@
<?php <?php
require dirname(__FILE__) . '/../vendor/bootstrap.php';
require dirname(__FILE__) . '/../min/config.php'; require dirname(__FILE__) . '/../min/config.php';
require "$min_libPath/Minify/Loader.php";
Minify_Loader::register();
// set cache path and doc root if configured // set cache path and doc root if configured
$minifyCachePath = isset($min_cachePath) $minifyCachePath = isset($min_cachePath)
? $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);