contributions/jcssmanager/behaviour/commands/jcssmanager/closure/compress.js.cmd.php
Go to the documentation of this file.00001 <?php 00002 Load::commands('jcssmanager/base/compress.base'); 00003 00004 class JCSSManagerCompressJSClosureCommand extends JCSSManagerCompressBaseCommand { 00005 /** 00006 * COmpress given files 00007 * 00008 * @return Status 00009 */ 00010 protected function compress($in_files, $out_file, &$files_to_unlink) { 00011 $ret = new Status(); 00012 if (count($in_files) > 0) { 00013 $ret->merge($this->run_closure($in_files, $out_file)); 00014 } 00015 00016 return $ret; 00017 } 00018 00019 /** 00020 * Returns type of compressed file 00021 * 00022 * @return string One of TYPE_X constants 00023 */ 00024 protected function get_db_type() { 00025 return JCSSManager::TYPE_JS; 00026 } 00027 00028 /** 00029 * Invoke Closure Compiler 00030 * 00031 * @param array $in_files 00032 * @param string $out_file 00033 * @return Status 00034 */ 00035 protected function run_closure($in_files, $out_file) { 00036 $ret = new Status(); 00037 00038 $module_dir = Load::get_module_dir('jcssmanager'); 00039 $options = ''; 00040 $options .= ' --charset=' . GyroLocale::get_charset(); 00041 $options .= ' --compilation_level=SIMPLE_OPTIMIZATIONS'; // WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS 00042 $options .= ' --third_party=1'; 00043 $options .= ' --warning_level=QUIET'; // QUIET, DEFAULT, VERBOSE 00044 foreach($in_files as $file) { 00045 if (substr($file, 0, 1) !== '/') { 00046 $file = Config::get_value(Config::URL_ABSPATH) . $file; 00047 } 00048 $options .= ' --js=' . $file; 00049 } 00050 $options .= ' --js_output_file=' . $out_file; 00051 $cmd = 'java -jar ' . $module_dir . '3rdparty/closure/compiler.jar' . $options; 00052 00053 Load::commands('generics/execute.shell'); 00054 $shell = new ExecuteShellCommand($cmd); 00055 $ret->merge($shell->execute()); 00056 00057 return $ret; 00058 } 00059 00060 }