I am trying to use Google Closure but called through a php library.
This is the code I'm trying to work with
https://code.google.com/p/php-closure/
So far it seems to be working well. However I now need to use the "Externs" feature of Google Closure.
I have gone through the php library code but I am unsure on how to add this feature. The library appears to call the Google Closure online API code, so I assume to add the externs feature I just need to pass the correct string attached to the correct variable.
I won't post the entire library here as it would be hard to read, but the efforts I've made to incorporate this feature.
To begin I added the variable to the library
var $_srcs = array();
var $_mode = "WHITESPACE_ONLY";
var $_warning_level = "DEFAULT";
var $_use_closure_library = false;
var $_pretty_print = false;
var $_debug = true;
var $_cache_dir = "";
var $_code_url_prefix = "";
var $_extern_file = ""; //my new code
add to the hash function
function _getHash() {
return md5(implode(",", $this->_srcs) . "-" .
$this->_mode . "-" .
$this->_warning_level . "-" .
$this->_use_closure_library . "-" .
$this->_pretty_print . "-" .
$this->_extern_file . "-" . //here again
$this->_debug);
}
add to get params list
function _getParamList() {
$params = array();
...
$params["warning_level"] = $this->_warning_level;
$params["extern_file"] = $this->_extern_file; //again here
if ($this->_pretty_print) $params["formatting"] = "pretty_print";
if ($this->_use_closure_library) $params["use_closure_library"] = "true";
$params["output_info_1"] = "compiled_code";
$params["output_info_2"] = "statistics";
$params["output_info_3"] = "warnings";
$params["output_info_4"] = "errors";
return $params;
}
my add externs file function
function externs($file) {
$this->_extern_file = $file;
return $this;
}
then my user call
$c->add("js/my-app.js")
->add("js/popup.js")
->externs("js/externs.js") //new code
->cacheDir("/tmp/js-cache/")
->write();
When trying to execute the code I get the same result as the original code. It appears the externs file that I'm trying to pass isn't being processed.
If anyone else is interested in this feature / library please feel free to post any ideas.
Thanks.