From d233b65d3dc183933c5be8a16b5b7eaf313ef66c Mon Sep 17 00:00:00 2001 From: Kaue Santoja Date: Wed, 2 Sep 2015 17:08:33 -0300 Subject: [PATCH] Adds config option to concatenate files only --- HISTORY.txt | 1 + MIN.txt | 5 +++++ min/config.php | 7 +++++++ min/index.php | 8 +++++++- min/lib/Minify.php | 25 +++++++++++++++++++------ min/lib/Minify/Controller/Base.php | 5 ++--- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index 9c44d16..464251c 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -2,6 +2,7 @@ Minify Release History (master) * Builder styled with Bootstrap (thanks to help from acidvertigo) + * Add config option for simply concatenating files Version 2.2.0 * Fix handling of RegEx in certain situations in JSMin diff --git a/MIN.txt b/MIN.txt index 5aaf0fb..e1b147a 100644 --- a/MIN.txt +++ b/MIN.txt @@ -176,6 +176,11 @@ file. To enable this, set $min_allowDebugFlag to true in config.php and append Known issue: files with comment-like strings/regexps can cause problems in this mode. +BYPASSING MINIFICATION + +See the $min_concatOnly option in config.php. + + QUESTIONS? http://groups.google.com/group/minify diff --git a/min/config.php b/min/config.php index ee757e1..3b5fd2b 100644 --- a/min/config.php +++ b/min/config.php @@ -12,6 +12,13 @@ */ $min_enableBuilder = false; + +/** + * Concatenate but do not minify the files. This can be used for testing. + */ +$min_concatOnly = false; + + /** * If non-empty, the Builder will be protected with HTTP Digest auth. * The username is "admin". diff --git a/min/index.php b/min/index.php index a49ad0b..f1bda95 100644 --- a/min/index.php +++ b/min/index.php @@ -52,6 +52,10 @@ if ($min_allowDebugFlag) { $min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']); } +if (!empty($min_concatOnly)) { + $min_serveOptions['concatOnly'] = true; +} + if ($min_errorLogger) { if (true === $min_errorLogger) { $min_errorLogger = FirePHP::getInstance(true); @@ -74,8 +78,10 @@ if (isset($_GET['g'])) { if (isset($_GET['f']) || isset($_GET['g'])) { if (! isset($min_serveController)) { $min_serveController = new Minify_Controller_MinApp(); - } + } + Minify::serve($min_serveController, $min_serveOptions); + } elseif ($min_enableBuilder) { header('Location: builder/'); diff --git a/min/lib/Minify.php b/min/lib/Minify.php index 9a4d286..516050c 100644 --- a/min/lib/Minify.php +++ b/min/lib/Minify.php @@ -124,6 +124,9 @@ class Minify { * 'debug' : set to true to minify all sources with the 'Lines' controller, which * eases the debugging of combined files. This also prevents 304 responses. * @see Minify_Lines::minify() + * + * 'concatOnly' : set to true to disable minification and simply concatenate the files. + * For JS, no minifier will be used. For CSS, only URI rewriting is still performed. * * 'minifiers' : to override Minify's default choice of minifier function for * a particular content-type, specify your callback under the key of the @@ -251,11 +254,21 @@ class Minify { $headers = $cg->getHeaders(); unset($cg); } - - if (self::$_options['contentType'] === self::TYPE_CSS - && self::$_options['rewriteCssUris']) { - foreach($controller->sources as $key => $source) { - if ($source->filepath + + if (self::$_options['concatOnly']) { + foreach ($controller->sources as $key => $source) { + if (self::$_options['contentType'] === self::TYPE_JS) { + $source->minifier = ""; + } elseif (self::$_options['contentType'] === self::TYPE_CSS) { + $source->minifier = array('Minify_CSS', 'minify'); + $source->minifyOptions['compress'] = false; + } + } + } + + if (self::$_options['contentType'] === self::TYPE_CSS && self::$_options['rewriteCssUris']) { + foreach ($controller->sources as $key => $source) { + if ($source->filepath && !isset($source->minifyOptions['currentDir']) && !isset($source->minifyOptions['prependRelativePath']) ) { @@ -493,7 +506,7 @@ class Minify { // get next source $source = null; if ($i < $l) { - $source = self::$_controller->sources[$i]; + $source = self::$_controller->sources[$i]; /* @var Minify_Source $source */ $sourceContent = $source->getContent(); diff --git a/min/lib/Minify/Controller/Base.php b/min/lib/Minify/Controller/Base.php index 5a86329..4e43013 100644 --- a/min/lib/Minify/Controller/Base.php +++ b/min/lib/Minify/Controller/Base.php @@ -51,6 +51,7 @@ abstract class Minify_Controller_Base { ,'bubbleCssImports' => false ,'quiet' => false // serve() will send headers and output ,'debug' => false + ,'concatOnly' => false // if you override these, the response codes MUST be directly after // the first space. @@ -145,9 +146,7 @@ abstract class Minify_Controller_Base { /** * instances of Minify_Source, which provide content and any individual minification needs. * - * @var array - * - * @see Minify_Source + * @var Minify_Source[] */ public $sources = array();