1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-31 01:29:56 +02:00

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`.
This commit is contained in:
Steve Clay
2016-02-27 01:13:28 -05:00
parent 0b466c0892
commit 4710509c68
30 changed files with 629 additions and 637 deletions

126
index.php
View File

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