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

Allow optional custom configs to be optional

This change tests first for the existence of the custom config variable and then the existence of each custom config file in turn. If found the directory path to append to that config file is changed to the custom path.

This allows fallback to the standard config when no custom config is present.

Maybe it would be even better to load both - the standard config, then the custom config, but this might be confusing for groupConfig.php. It could work using array merge, but it wouldn't be particularly clear or easy to explain.
This commit is contained in:
Sam Bauers
2014-02-04 12:37:40 +11:00
parent b8a0cac0e5
commit ae70500a2d

View File

@@ -9,17 +9,35 @@
define('MINIFY_MIN_DIR', dirname(__FILE__));
// set config directory defaults
$min_configDirs = array(
'config.php' => MINIFY_MIN_DIR,
'config-test.php' => MINIFY_MIN_DIR,
'groupsConfig.php' => MINIFY_MIN_DIR
);
// check for custom config directory
if (defined('MINIFY_CUSTOM_CONFIG_DIR')) {
define('MINIFY_CONFIG_DIR', MINIFY_CUSTOM_CONFIG_DIR);
} else {
define('MINIFY_CONFIG_DIR', MINIFY_MIN_DIR);
// check for each config in the custom directory
foreach ($min_configDirs as $file => $dir) {
$path = MINIFY_CUSTOM_CONFIG_DIR . '/' . $file;
if (!file_exists($path)) {
continue;
}
if (!is_readable($path)) {
continue;
}
// reassign the directory for this config to custom
$min_configDirs[$file] = MINIFY_CUSTOM_CONFIG_DIR;
}
unset($file, $dir, $path);
}
// load config
require MINIFY_CONFIG_DIR . '/config.php';
require $min_configDirs['config.php'] . '/config.php';
if (isset($_GET['test'])) {
include MINIFY_CONFIG_DIR . '/config-test.php';
include $min_configDirs['config-test.php'] . '/config-test.php';
}
require "$min_libPath/Minify/Loader.php";
@@ -59,7 +77,7 @@ if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
}
if (isset($_GET['g'])) {
// well need groups config
$min_serveOptions['minApp']['groups'] = (require MINIFY_CONFIG_DIR . '/groupsConfig.php');
$min_serveOptions['minApp']['groups'] = (require $min_configDirs['groupsConfig.php'] . '/groupsConfig.php');
}
if (isset($_GET['f']) || isset($_GET['g'])) {
// serve!