From 237d83d3cbc48975c5cfee6c7329b1203e10a3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 3 Feb 2016 09:08:31 +0200 Subject: [PATCH] add jshrink thin wrapper --- composer.json | 3 ++- lib/Minify/JS/JShrink.php | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lib/Minify/JS/JShrink.php diff --git a/composer.json b/composer.json index 7842db1..6f0e5c1 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "require-dev": { "leafo/lessphp": "~0.4.0", "meenie/javascript-packer": "~1.1", - "phpunit/phpunit": "4.8.*" + "phpunit/phpunit": "4.8.*", + "tedivm/jshrink": "~1.1.0" }, "suggest": { "leafo/lessphp": "LESS support", diff --git a/lib/Minify/JS/JShrink.php b/lib/Minify/JS/JShrink.php new file mode 100644 index 0000000..d5dcf8c --- /dev/null +++ b/lib/Minify/JS/JShrink.php @@ -0,0 +1,47 @@ + + * @link https://github.com/tedious/JShrink + * + */ +class JShrink +{ + /** + * Contains the default options for minification. This array is merged with + * the one passed in by the user to create the request specific set of + * options (stored in the $options attribute). + * + * @var string[] + */ + protected static $defaultOptions = array('flaggedComments' => true); + + /** + * Takes a string containing javascript and removes unneeded characters in + * order to shrink the code without altering it's functionality. + * + * @param string $js The raw javascript to be minified + * @param array $options Various runtime options in an associative array + * + * @see JShrink\Minifier::minify() + * @return string + */ + public static function minify($js, array $options = array()) + { + $options = array_merge( + self::$defaultOptions, + $options + ); + return \JShrink\Minifier::minify($js, $options); + } +}