1
0
mirror of https://github.com/mrclay/minify.git synced 2025-02-19 22:44:56 +01:00
minify/index.php

113 lines
3.0 KiB
PHP
Raw Normal View History

<?php
/**
* Sets up MinApp controller and serves files
*
* DO NOT EDIT! Configure this utility via config.php and groupsConfig.php
*
* @package Minify
*/
require __DIR__ . '/bootstrap.php';
// 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
2014-02-05 00:59:21 +11:00
require $min_configPaths['base'];
2012-03-15 14:00:50 -04:00
if (isset($_GET['test'])) {
2014-02-05 00:57:18 +11:00
include $min_configPaths['test'];
2012-03-15 14:00:50 -04:00
}
// 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,
));
// setup cache
if (!isset($min_cachePath)) {
$min_cachePath = '';
}
if (is_string($min_cachePath)) {
$cache = new Minify_Cache_File($min_cachePath, $min_cacheFileLocking);
} else {
$cache = $min_cachePath;
}
2014-09-23 11:09:09 -04:00
$server = new Minify($cache);
// TODO probably should do this elsewhere...
2014-09-23 11:09:09 -04:00
$min_serveOptions['minifierOptions']['text/css']['docRoot'] = $env->getDocRoot();
$min_serveOptions['minifierOptions']['text/css']['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
2014-09-23 11:09:09 -04:00
$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
2014-09-23 11:09:09 -04:00
if (null !== $env->get('v') || preg_match('/&\\d/', $env->server('QUERY_STRING'))) {
$min_serveOptions['maxAge'] = 31536000;
}
2014-02-04 11:00:25 -05:00
// need groups config?
2014-09-23 11:09:09 -04:00
if (null !== $env->get('g')) {
// well need groups config
2014-02-05 00:57:18 +11:00
$min_serveOptions['minApp']['groups'] = (require $min_configPaths['groups']);
}
2014-09-23 11:09:09 -04:00
if ($env->get('f') || null !== $env->get('g')) {
// serving!
if (! isset($min_serveController)) {
2014-09-23 11:09:09 -04:00
$sourceFactoryOptions = array();
// translate legacy setting to option for source factory
if (isset($min_serveOptions['minApp']['noMinPattern'])) {
$sourceFactoryOptions['noMinPattern'] = $min_serveOptions['minApp']['noMinPattern'];
}
2014-09-27 16:18:23 +03:00
$sourceFactory = new Minify_Source_Factory($env, $sourceFactoryOptions, $cache);
2014-09-23 11:09:09 -04:00
$min_serveController = new Minify_Controller_MinApp($env, $sourceFactory);
}
$server->serve($min_serveController, $min_serveOptions);
2014-09-20 10:47:59 +02:00
exit;
2014-09-23 11:09:09 -04:00
}
2014-09-23 11:09:09 -04:00
// not serving
if ($min_enableBuilder) {
header('Location: builder/');
2014-09-20 10:47:59 +02:00
exit;
}
2014-09-23 11:09:09 -04:00
header('Location: /');
exit;