5 class Script extends \Rsi\Fred\Minify\Handler{
9 protected $_url =
'https://closure-compiler.appspot.com/compile?compilation_level=SIMPLE_OPTIMIZATIONS&output_format=json&warning_level=verbose&output_info=compiled_code&output_info=errors&output_info=warnings';
12 protected function local($script,$filename = null){
13 if(!$this->_java || !$this->_jar)
return false;
14 $source = \Rsi\File::tempFile(
'js',$script);
15 $target = \Rsi\File::tempFile(
'js');
16 exec(
"{$this->_java} -jar {$this->_jar} --js $source --js_output_file $target");
17 $result = file_get_contents($target);
23 protected function service($script,$filename = null){
24 $ch = curl_init($this->_url);
25 curl_setopt($ch,CURLOPT_POSTFIELDS,
'js_code=' . urlencode($script));
26 curl_setopt($ch,CURLOPT_RETURNTRANSFER,
true);
27 $response = curl_exec($ch);
30 if($data = json_decode($response)){
32 if(property_exists($data,$property = $key .
's'))
foreach($data->$property as $message){
33 foreach($this->_ignore as $ignore)
if(preg_match($ignore,$message->$key))
continue 2;
34 $this->_minify->log->add($prio,
"Script $key: {$message->$key}",$filename,$message->lineno,(array)$message);
36 return $data->compiledCode;
38 else $this->_minify->log->error(
'Invalid response',__FILE__,__LINE__,[
'response' => $response,
'error' => json_last_error_msg()]);
40 else $this->_minify->log->error(
'No response',__FILE__,__LINE__,[
'url' => $this->_url]);
44 public function source($source,$filename = null){
46 return ($this->
local($source,$filename) ?: $this->
service($source,$filename)) ?: $source;
49 $this->_minify->log->error(
'Error while minimizing script: ' . $e->getMessage(),__FILE__,__LINE__);
service($script, $filename=null)
const NOTICE
Normal, but significant, condition.
const ERROR
Error conditions.
local($script, $filename=null)
Framework for Rapid and Easy Development.
$_ignore
Regex's for compiler messages to ignore.
source($source, $filename=null)