2015-10-23 02:51:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\View;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use Exception;
|
2015-10-23 02:51:26 +02:00
|
|
|
use JSMin;
|
|
|
|
|
|
|
|
class JSMinifier implements Requirements_Minifier {
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2015-10-23 02:51:26 +02:00
|
|
|
public function minify($content, $type, $filename) {
|
|
|
|
// Non-js files aren't minified
|
|
|
|
if($type !== 'js') {
|
|
|
|
return $content . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine JS
|
|
|
|
try {
|
|
|
|
require_once('thirdparty/jsmin/jsmin.php');
|
|
|
|
increase_time_limit_to();
|
|
|
|
$content = JSMin::minify($content);
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$message = $e->getMessage();
|
|
|
|
user_error("Failed to minify {$filename}, exception: {$message}", E_USER_WARNING);
|
|
|
|
} finally {
|
|
|
|
return $content . ";\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|