Skip to content
Permalink
Browse files

Large restructuring

Moves all dependency building into App
bootstrap.php returns an App instance
The app loads config files as necessary
Moves logging to Monolog
Moves HTTP digest auth to packagist component
Rely on sys_get_temp_dir
Env hosts $_POST and allows defaults when reading
HTML helper uses the App and can handle less files
Source factory assumes strings are filenames
Fixes JsClosureCompilerTest::test6 (API now handles ES5 by default)
Exclude JsClosureCompilerTest due to API limitations
config.php can now return a Minify\Config object
Variables set in config.php are now moved to a `Minify\Config` object,
allowing better static analysis.
The `zlib.output_compression` set is moved into `Minify::serve`.
  • Loading branch information...
mrclay committed Feb 27, 2016
1 parent 0b466c0 commit 4710509c689ee60288d51768193c2fbc86bca6f4
@@ -1,12 +1,15 @@
## 3.0 progress
* Better CSS minification via Túbal Martín's CSSMin
* Docs overhaul
* New API incompatible with the 2.x versions
## Version 3.0.0 (unreleased)
* The project root is now what is deployed as `min`
* Installation requires use of Composer to install dependencies
* Removes JSMin+ (unmaintained, high memory usage)
* Removes DooDigestAuth
* Removes Minify_Loader (uses Composer)
* Removes Minify_Logger (uses Monolog)
* The Minify, source, and controller components have changed APIs
* Better CSS minification via Túbal Martín's CSSMin
* Add config option for simply concatenating files
* Add config option for altering creation of Minify/MinApp objects
* Missing spec no longer redirects, instead links to docs
* Removed JSMin+ (unmaintained, high memory usage)

## Version 2.2.1 (2014-10-30)
* Builder styled with Bootstrap (thanks to help from acidvertigo)
@@ -1,8 +1,6 @@
<?php
/**
* Sets up autoloader for Minify
*
* @package Minify
* Sets up autoloading and returns the Minify\App
*/
call_user_func(function () {
@@ -15,3 +13,5 @@
}
require $file;
});
return new \Minify\App(__DIR__);
@@ -1,13 +1,14 @@
<?php
// check for auto-encoding
$encodeOutput = (function_exists('gzdeflate')
&& !ini_get('zlib.output_compression'));
$app = (require __DIR__ . '/../bootstrap.php');
/* @var \Minify\App $app */
$config = $app->config;
// recommend $min_symlinks setting for Apache UserDir
$symlinkOption = '';
if (0 === strpos($_SERVER["SERVER_SOFTWARE"], 'Apache/')
&& preg_match('@^/\\~(\\w+)/@', $_SERVER['REQUEST_URI'], $m)
if (0 === strpos($app->env->server("SERVER_SOFTWARE"), 'Apache/')
&& preg_match('@^/\\~(\\w+)/@', $app->env->server('REQUEST_URI'), $m)
) {
$userDir = DIRECTORY_SEPARATOR . $m[1] . DIRECTORY_SEPARATOR;
if (false !== strpos(__FILE__, $userDir)) {
@@ -18,24 +19,19 @@
}
}
require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/../config.php';
if (! $min_enableBuilder) {
if (!$config->enableBuilder) {
header('Content-Type: text/plain');
die('This application is not enabled. See https://github.com/mrclay/minify/blob/master/docs/BuilderApp.wiki.md');
}
if (isset($min_builderPassword)
&& is_string($min_builderPassword)
&& $min_builderPassword !== '') {
DooDigestAuth::http_auth('Minify Builder', array('admin' => $min_builderPassword));
}
$cachePathCode = '';
if (! isset($min_cachePath) && ! function_exists('sys_get_temp_dir')) {
$detectedTmp = Minify_Cache_File::tmp();
$cachePathCode = "\$min_cachePath = " . var_export($detectedTmp, 1) . ';';
if ($config->builderPassword && $config->builderPassword !== '') {
$auth = new Intervention\Httpauth\Httpauth(array(
'username' => 'admin',
'password' => $config->builderPassword,
'type' => 'digest',
'realm' => 'Minify Builder',
));
$auth->secure();
}
ob_start();
@@ -79,13 +75,6 @@
FirePHP console will report the cause of the error.
</p>

<?php if ($cachePathCode): ?>
<p class=topNote><strong>Note:</strong> <code><?php echo
htmlspecialchars($detectedTmp); ?></code> was discovered as a usable temp directory.<br>To
slightly improve performance you can hardcode this in /min/config.php:
<code><?php echo htmlspecialchars($cachePathCode); ?></code></p>
<?php endIf; ?>

<p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which
<a href="http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/"
@@ -106,7 +95,7 @@

<div id=bmUris></div>

<p><button class="btn btn-primary" id=update class=hide>Update</button></p>
<p><button class="btn btn-primary hide" id=update>Update</button></p>

<div id=results class=hide>

@@ -218,26 +207,8 @@
<?php
$content = ob_get_clean();
if (!isset($min_cachePath)) {
$min_cachePath = '';
}
if (is_string($min_cachePath)) {
$cache = new Minify_Cache_File($min_cachePath, $min_cacheFileLocking);
} else {
$cache = $min_cachePath;
}
$env = new Minify_Env();
$sourceFactory = new Minify_Source_Factory($env, array(
'uploaderHoursBehind' => $min_uploaderHoursBehind,
));
$controller = new Minify_Controller_Page($env, $sourceFactory);
$server = new Minify($cache);
$server->serve($controller, array(
$controller = new Minify_Controller_Page($app->env, $app->sourceFactory);
$minify = $app->minify->serve($controller, array(
'content' => $content,
'id' => __FILE__,
'lastModifiedTime' => max(
@@ -247,5 +218,4 @@
filemtime(__DIR__ . '/../lib/Minify.php')
),
'minifyAll' => true,
'encodeOutput' => $encodeOutput,
));
@@ -5,18 +5,18 @@
* @package Minify
*/
require __DIR__ . '/../bootstrap.php';
$app = (require __DIR__ . '/../bootstrap.php');
/* @var \Minify\App $app */
$_oc = ini_get('zlib.output_compression');
// allow access only if builder is enabled
require __DIR__ . '/../config.php';
if (! $min_enableBuilder) {
if (!$app->config->enableBuilder) {
header('Location: /');
exit;
}
if (isset($_GET['hello'])) {
if ($app->env->get('hello')) {
// echo 'World!'
// try to prevent double encoding (may not have an effect)
@@ -23,10 +23,13 @@
"classmap": ["tests/TestCase.php"]
},
"require": {
"php": ">=5.3.0",
"ext-pcre": "*",
"firephp/firephp-core": "~0.4.0",
"intervention/httpauth": "~2.0",
"monolog/monolog": "~1.1",
"mrclay/jsmin-php": "~2",
"php": ">=5.3.0",
"mrclay/props-dic": "^2.2",
"tubalmartin/cssmin": "~2.4.8"
},
"require-dev": {
@@ -27,12 +27,8 @@
/**
* Set to true to log messages to FirePHP (Firefox Firebug addon).
* Set to true to log messages to FirePHP (Firefox Firebug addon) and PHP's error_log
* Set to false for no error logging (Minify may be slightly faster).
* @link http://www.firephp.org/
*
* If you want to use a custom error logger, set this to your logger
* instance. Your object should have a method log(string $message).
*/
$min_errorLogger = false;
@@ -193,9 +189,6 @@
*
* You can see the default implementations (and what gets passed in) in index.php.
*/
//$min_factories['minify'] = ... a callable
//$min_factories['controller'] = ... a callable
//$min_factories['minify'] = ... a callable accepting a Minify\App object
//$min_factories['controller'] = ... a callable accepting a Minify\App object
// try to disable output_compression (may not have an effect)
ini_set('zlib.output_compression', '0');
@@ -12,8 +12,8 @@
**/
return array(
// 'testJs' => array('//minify/min/quick-test.js'),
// 'testCss' => array('//minify/min/quick-test.css'),
// 'testJs' => array('//minify/quick-test.js'),
// 'testCss' => array('//minify/quick-test.css'),
// 'js' => array('//js/file1.js', '//js/file2.js'),
// 'css' => array('//css/file1.css', '//css/file2.css'),
);
);
126 index.php
@@ -7,127 +7,7 @@
* @package Minify
*/
require __DIR__ . '/bootstrap.php';
$app = (require __DIR__ . '/bootstrap.php');
/* @var \Minify\App $app */
// set config path defaults
$min_configPaths = array(
'base' => __DIR__ . '/config.php',
'test' => __DIR__ . '/config-test.php',
'groups' => __DIR__ . '/groupsConfig.php',
);
// check for custom config paths
if (!empty($min_customConfigPaths) && is_array($min_customConfigPaths)) {
$min_configPaths = array_merge($min_configPaths, $min_customConfigPaths);
}
// load config
require $min_configPaths['base'];
if (isset($_GET['test'])) {
include $min_configPaths['test'];
}
// setup factories
$defaultFactories = array(
'minify' => function (Minify_CacheInterface $cache) {
return new Minify($cache);
},
'controller' => function (Minify_Env $env, Minify_Source_Factory $sourceFactory) {
return new Minify_Controller_MinApp($env, $sourceFactory);
},
);
if (!isset($min_factories)) {
$min_factories = array();
}
$min_factories = array_merge($defaultFactories, $min_factories);
// use an environment object to encapsulate all input
$server = $_SERVER;
if ($min_documentRoot) {
$server['DOCUMENT_ROOT'] = $min_documentRoot;
}
$env = new Minify_Env(array(
'server' => $server,
));
// TODO probably should do this elsewhere...
$min_serveOptions['minifierOptions']['text/css']['docRoot'] = $env->getDocRoot();
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
$min_serveOptions['minApp']['symlinks'] = $min_symlinks;
// auto-add targets to allowDirs
foreach ($min_symlinks as $uri => $target) {
$min_serveOptions['minApp']['allowDirs'][] = $target;
}
if ($min_allowDebugFlag) {
// TODO get rid of static stuff
$min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($env);
}
if (!empty($min_concatOnly)) {
$min_serveOptions['concatOnly'] = true;
}
if ($min_errorLogger) {
if (true === $min_errorLogger) {
$min_errorLogger = FirePHP::getInstance(true);
}
// TODO get rid of global state
Minify_Logger::setLogger($min_errorLogger);
}
// check for URI versioning
if (null !== $env->get('v') || preg_match('/&\\d/', $env->server('QUERY_STRING'))) {
$min_serveOptions['maxAge'] = 31536000;
}
// need groups config?
if (null !== $env->get('g')) {
// we need groups config
$min_serveOptions['minApp']['groups'] = (require $min_configPaths['groups']);
}
// cache defaults
if (!isset($min_cachePath)) {
$min_cachePath = '';
}
if (!isset($min_cacheFileLocking)) {
$min_cacheFileLocking = true;
}
if (is_string($min_cachePath)) {
$cache = new Minify_Cache_File($min_cachePath, $min_cacheFileLocking);
} else {
// assume it meets interface.
$cache = $min_cachePath;
}
/* @var Minify_CacheInterface $cache */
$minify = call_user_func($min_factories['minify'], $cache);
/* @var Minify $minify */
if (!$env->get('f') && $env->get('g') === null) {
// no spec given
$msg = '<p>No "f" or "g" parameters were detected.</p>';
$url = 'https://github.com/mrclay/minify/blob/master/docs/CommonProblems.wiki.md#long-url-parameters-are-ignored';
$defaults = $minify->getDefaultOptions();
$minify->errorExit($defaults['badRequestHeader'], $url, $msg);
}
$sourceFactoryOptions = array();
// translate legacy setting to option for source factory
if (isset($min_serveOptions['minApp']['noMinPattern'])) {
$sourceFactoryOptions['noMinPattern'] = $min_serveOptions['minApp']['noMinPattern'];
}
if (isset($min_serveOptions['minApp']['allowDirs'])) {
$sourceFactoryOptions['allowDirs'] = $min_serveOptions['minApp']['allowDirs'];
}
$sourceFactory = new Minify_Source_Factory($env, $sourceFactoryOptions, $cache);
$controller = call_user_func($min_factories['controller'], $env, $sourceFactory);
/* @var Minify_ControllerInterface $controller */
$minify->serve($controller, $min_serveOptions);
$app->runServer();

0 comments on commit 4710509

Please sign in to comment.
You can’t perform that action at this time.