diff --git a/lib/Minify/ClosureCompiler.php b/lib/Minify/ClosureCompiler.php index 487cafe..26cbc67 100644 --- a/lib/Minify/ClosureCompiler.php +++ b/lib/Minify/ClosureCompiler.php @@ -24,19 +24,12 @@ * * * - * @todo unit tests, $options docs - * @todo more options support (or should just passthru them all?) - * * @package Minify * @author Stephen Clay * @author Elan Ruusamäe */ class Minify_ClosureCompiler { - const OPTION_CHARSET = 'charset'; - const OPTION_COMPILATION_LEVEL = 'compilation_level'; - const OPTION_WARNING_LEVEL = 'warning_level'; - public static $isDebug = false; /** @@ -61,6 +54,17 @@ class Minify_ClosureCompiler */ public static $javaExecutable = 'java'; + /** + * Default command line options passed to closure-compiler + * + * @var array + */ + public static $defaultOptions = array( + 'charset' => 'utf-8', + 'compilation_level' => 'SIMPLE_OPTIMIZATIONS', + 'warning_level' => 'QUIET', + ); + /** * Minify a Javascript string * @@ -137,7 +141,8 @@ class Minify_ClosureCompiler $this->checkJar(self::$jarFile); $server = array( self::$javaExecutable, - '-jar', escapeshellarg(self::$jarFile) + '-jar', + escapeshellarg(self::$jarFile) ); return $server; @@ -151,24 +156,13 @@ class Minify_ClosureCompiler { $args = array(); - $o = array_merge( - array( - self::OPTION_CHARSET => 'utf-8', - self::OPTION_COMPILATION_LEVEL => 'SIMPLE_OPTIMIZATIONS', - self::OPTION_WARNING_LEVEL => 'QUIET', - ), + $options = array_merge( + static::$defaultOptions, $userOptions ); - $charsetOption = $o[self::OPTION_CHARSET]; - if (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $charsetOption)) { - $args[] = "--charset {$charsetOption}"; - } - - foreach (array(self::OPTION_COMPILATION_LEVEL, self::OPTION_WARNING_LEVEL) as $opt) { - if ($o[$opt]) { - $args[] = "--{$opt} " . escapeshellarg($o[$opt]); - } + foreach ($options as $key => $value) { + $args[] = "--{$key} " . escapeshellarg($value); } return $args; diff --git a/tests/MinifyClosureCompilerTest.php b/tests/MinifyClosureCompilerTest.php index 13c88d0..15a1d5f 100644 --- a/tests/MinifyClosureCompilerTest.php +++ b/tests/MinifyClosureCompilerTest.php @@ -63,7 +63,7 @@ class MinifyClosureCompilerTest extends TestCase $src = "function unused() {};"; $minExpected = ''; $options = array( - Minify_ClosureCompiler::OPTION_COMPILATION_LEVEL => 'ADVANCED_OPTIMIZATIONS' + 'compilation_level' => 'ADVANCED_OPTIMIZATIONS' ); $minOutput = Minify_ClosureCompiler::minify($src, $options); $this->assertSame($minExpected, $minOutput, 'advanced optimizations');