From ae70500a2d48f927334d334ec18e1e3fc0bc9e35 Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Tue, 4 Feb 2014 12:37:40 +1100 Subject: [PATCH] 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. --- min/index.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/min/index.php b/min/index.php index 3d2329d..9207fa3 100644 --- a/min/index.php +++ b/min/index.php @@ -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!