1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-12 09:05:08 +02:00

pass any option to closure compiler

This commit is contained in:
Elan Ruusamäe
2016-12-06 16:59:36 +02:00
parent 8949df33dd
commit 6a330d9091
2 changed files with 18 additions and 24 deletions

View File

@@ -24,19 +24,12 @@
*
* </code>
*
* @todo unit tests, $options docs
* @todo more options support (or should just passthru them all?)
*
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
* @author Elan Ruusamäe <glen@delfi.ee>
*/
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;