From aceef480c33d7126229258ab6c739319ee611c6b Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Mon, 3 Feb 2014 18:19:00 +1100 Subject: [PATCH 01/10] Allow definition of custom config directory. To allow "clean" checkouts of Minify we could use the possibility to define a custom config directory outside the minify directory. Using this patch a user can define MINIFY_CUSTOM_CONFIG_DIR on a new page outside the minify directory and then include minify's index.php on that page and point their rewrites etc. there instead. The config.php (and config-test.php) could be copied to the custom directory and edited without causing svn:external/git:submodule conflicts. --- min/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/min/index.php b/min/index.php index 79b047d..f9f994b 100644 --- a/min/index.php +++ b/min/index.php @@ -9,11 +9,17 @@ define('MINIFY_MIN_DIR', dirname(__FILE__)); +if (defined('MINIFY_CUSTOM_CONFIG_DIR')) { + define('MINIFY_CONFIG_DIR', MINIFY_CUSTOM_CONFIG_DIR); +} else { + define('MINIFY_CONFIG_DIR', MINIFY_MIN_DIR); +} + // load config -require MINIFY_MIN_DIR . '/config.php'; +require MINIFY_CONFIG_DIR . '/config.php'; if (isset($_GET['test'])) { - include MINIFY_MIN_DIR . '/config-test.php'; + include MINIFY_CONFIG_DIR . '/config-test.php'; } require "$min_libPath/Minify/Loader.php"; @@ -69,4 +75,4 @@ if (isset($_GET['f']) || isset($_GET['g'])) { } else { header("Location: /"); exit(); -} \ No newline at end of file +} From 719c22fca4e56112e442a512053c8d9bad46280f Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Mon, 3 Feb 2014 18:19:46 +1100 Subject: [PATCH 02/10] Include groupsConfig.php in MINIFY_CONFIG_DIR. --- min/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/min/index.php b/min/index.php index f9f994b..3d2329d 100644 --- a/min/index.php +++ b/min/index.php @@ -59,7 +59,7 @@ if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) { } if (isset($_GET['g'])) { // well need groups config - $min_serveOptions['minApp']['groups'] = (require MINIFY_MIN_DIR . '/groupsConfig.php'); + $min_serveOptions['minApp']['groups'] = (require MINIFY_CONFIG_DIR . '/groupsConfig.php'); } if (isset($_GET['f']) || isset($_GET['g'])) { // serve! From b8a0cac0e519719228d4156f08fdefdc3c63f377 Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Tue, 4 Feb 2014 12:13:33 +1100 Subject: [PATCH 03/10] Explain separate config storage in MIN.txt --- MIN.txt | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/MIN.txt b/MIN.txt index dbeff0f..8a42c4e 100644 --- a/MIN.txt +++ b/MIN.txt @@ -130,6 +130,37 @@ $cssUri = Minify_getUri(array( echo ""; +STORING CONFIG FILES OUTSIDE THE MINIFY DIRECTORY + +It is possible to store config files (config.php, config-test.php, groupsConfig.php) +in a custom directory outside the Minify directory. This is useful if you wish to +include Minify as an external dependency inside another project via SVN external or +Git submodule inclusion. + +For example, let's assume you have a Minify directory "min" in your site root. Then +you could create a new directory called "min-configs" in the site root. Copy any +config files you wish to modify to "min-configs", and modify as desired. + +Then create a new file, for example "min.php" in your site root. The contents of +this file could look like this: + + '/min.php')); +echo ""; + + DEBUG MODE In debug mode, instead of compressing files, Minify sends combined files with @@ -142,4 +173,4 @@ Known issue: files with comment-like strings/regexps can cause problems in this QUESTIONS? -http://groups.google.com/group/minify \ No newline at end of file +http://groups.google.com/group/minify From ae70500a2d48f927334d334ec18e1e3fc0bc9e35 Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Tue, 4 Feb 2014 12:37:40 +1100 Subject: [PATCH 04/10] 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! From b34d964e886adde76a64770bab813de6e112dd0d Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Wed, 5 Feb 2014 00:46:08 +1100 Subject: [PATCH 05/10] Allow full custom path including filename --- min/index.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/min/index.php b/min/index.php index 9207fa3..05e83e1 100644 --- a/min/index.php +++ b/min/index.php @@ -9,35 +9,37 @@ 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 +// set config path defaults +$min_configPaths = array( + 'standard' => MINIFY_MIN_DIR . '/config.php', + 'test' => MINIFY_MIN_DIR . '/config-test.php', + 'groups' => MINIFY_MIN_DIR . '/groupsConfig.php' ); -// check for custom config directory -if (defined('MINIFY_CUSTOM_CONFIG_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)) { +// check for custom config paths +if (!empty($min_customConfigPaths)) { + // check for each config in the custom path + foreach ($min_configPaths as $key => $path) { + if (!empty($min_customConfigPaths[$key])) { + continue; + } + if (!file_exists($min_customConfigPaths[$key])) { continue; } - if (!is_readable($path)) { + if (!is_readable($min_customConfigPaths[$key])) { continue; } - // reassign the directory for this config to custom - $min_configDirs[$file] = MINIFY_CUSTOM_CONFIG_DIR; + // reassign the path for this config to custom + $min_configPaths[$key] = $min_customConfigPaths[$key]; } - unset($file, $dir, $path); + unset($key, $path); } // load config -require $min_configDirs['config.php'] . '/config.php'; +require $min_configPaths['config.php'] . '/config.php'; if (isset($_GET['test'])) { - include $min_configDirs['config-test.php'] . '/config-test.php'; + include $min_configPaths['config-test.php'] . '/config-test.php'; } require "$min_libPath/Minify/Loader.php"; @@ -77,7 +79,7 @@ if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) { } if (isset($_GET['g'])) { // well need groups config - $min_serveOptions['minApp']['groups'] = (require $min_configDirs['groupsConfig.php'] . '/groupsConfig.php'); + $min_serveOptions['minApp']['groups'] = (require $min_configPaths['groupsConfig.php'] . '/groupsConfig.php'); } if (isset($_GET['f']) || isset($_GET['g'])) { // serve! From 0f4692e0c0871ffee117febb0ca3751d8b0481ed Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Wed, 5 Feb 2014 00:51:23 +1100 Subject: [PATCH 06/10] Change custom path explanation to match full custom paths changes. --- MIN.txt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/MIN.txt b/MIN.txt index 8a42c4e..5b593ca 100644 --- a/MIN.txt +++ b/MIN.txt @@ -132,10 +132,10 @@ echo ""; STORING CONFIG FILES OUTSIDE THE MINIFY DIRECTORY -It is possible to store config files (config.php, config-test.php, groupsConfig.php) -in a custom directory outside the Minify directory. This is useful if you wish to -include Minify as an external dependency inside another project via SVN external or -Git submodule inclusion. +It is possible to store config files (min/config.php, min/config-test.php, +min/groupsConfig.php) in a custom directory outside the Minify directory. This is +useful if you wish to include Minify as an external dependency inside another +project via SVN external or Git submodule inclusion. For example, let's assume you have a Minify directory "min" in your site root. Then you could create a new directory called "min-configs" in the site root. Copy any @@ -145,13 +145,18 @@ Then create a new file, for example "min.php" in your site root. The contents of this file could look like this: $customConfigDirectory . '/config.php', + 'test' => $customConfigDirectory . '/config-test.php', + 'groups' => $customConfigDirectory . '/groupsConfig.php' +); include_once 'min/index.php'; You would then reference min.php in your JS and CSS links instead of min/index.php. -This method will also affect those using the Minify_getUri() function. You will need +This method will affect those using the Minify_getUri() function. You will need to add options to calls to that function, e.g.: Date: Wed, 5 Feb 2014 00:54:03 +1100 Subject: [PATCH 07/10] Remove filenames from include statements. --- min/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/min/index.php b/min/index.php index 05e83e1..435330f 100644 --- a/min/index.php +++ b/min/index.php @@ -36,10 +36,10 @@ if (!empty($min_customConfigPaths)) { } // load config -require $min_configPaths['config.php'] . '/config.php'; +require $min_configPaths['config.php']; if (isset($_GET['test'])) { - include $min_configPaths['config-test.php'] . '/config-test.php'; + include $min_configPaths['config-test.php']; } require "$min_libPath/Minify/Loader.php"; @@ -79,7 +79,7 @@ if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) { } if (isset($_GET['g'])) { // well need groups config - $min_serveOptions['minApp']['groups'] = (require $min_configPaths['groupsConfig.php'] . '/groupsConfig.php'); + $min_serveOptions['minApp']['groups'] = (require $min_configPaths['groupsConfig.php']); } if (isset($_GET['f']) || isset($_GET['g'])) { // serve! From 2c897a0b59f0e98638ec9a8625a6dc370338600d Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Wed, 5 Feb 2014 00:57:18 +1100 Subject: [PATCH 08/10] Fix index names on config paths array. --- min/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/min/index.php b/min/index.php index 435330f..f191f26 100644 --- a/min/index.php +++ b/min/index.php @@ -36,10 +36,10 @@ if (!empty($min_customConfigPaths)) { } // load config -require $min_configPaths['config.php']; +require $min_configPaths['standard']; if (isset($_GET['test'])) { - include $min_configPaths['config-test.php']; + include $min_configPaths['test']; } require "$min_libPath/Minify/Loader.php"; @@ -79,7 +79,7 @@ if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) { } if (isset($_GET['g'])) { // well need groups config - $min_serveOptions['minApp']['groups'] = (require $min_configPaths['groupsConfig.php']); + $min_serveOptions['minApp']['groups'] = (require $min_configPaths['groups']); } if (isset($_GET['f']) || isset($_GET['g'])) { // serve! From 8e55cd809152e72943158a6cdce0da317c1f647d Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Wed, 5 Feb 2014 00:58:46 +1100 Subject: [PATCH 09/10] Use base for main config key. --- MIN.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MIN.txt b/MIN.txt index 5b593ca..e7181d7 100644 --- a/MIN.txt +++ b/MIN.txt @@ -147,9 +147,9 @@ this file could look like this: $customConfigDirectory . '/config.php', - 'test' => $customConfigDirectory . '/config-test.php', - 'groups' => $customConfigDirectory . '/groupsConfig.php' + 'base' => $customConfigDirectory . '/config.php', + 'test' => $customConfigDirectory . '/config-test.php', + 'groups' => $customConfigDirectory . '/groupsConfig.php' ); include_once 'min/index.php'; From 8e74d727f02ef0f4e932247cc1313dccad4f81ee Mon Sep 17 00:00:00 2001 From: Sam Bauers Date: Wed, 5 Feb 2014 00:59:21 +1100 Subject: [PATCH 10/10] Use base for main config key. --- min/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/min/index.php b/min/index.php index f191f26..6f00ffd 100644 --- a/min/index.php +++ b/min/index.php @@ -11,9 +11,9 @@ define('MINIFY_MIN_DIR', dirname(__FILE__)); // set config path defaults $min_configPaths = array( - 'standard' => MINIFY_MIN_DIR . '/config.php', - 'test' => MINIFY_MIN_DIR . '/config-test.php', - 'groups' => MINIFY_MIN_DIR . '/groupsConfig.php' + 'base' => MINIFY_MIN_DIR . '/config.php', + 'test' => MINIFY_MIN_DIR . '/config-test.php', + 'groups' => MINIFY_MIN_DIR . '/groupsConfig.php' ); // check for custom config paths @@ -36,7 +36,7 @@ if (!empty($min_customConfigPaths)) { } // load config -require $min_configPaths['standard']; +require $min_configPaths['base']; if (isset($_GET['test'])) { include $min_configPaths['test'];