douxu2467 2015-03-07 20:53
浏览 39

谷歌关闭通过PHP与Externs

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
    • ¥15 NX MCD仿真与博途通讯不了啥情况
    • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
    • ¥15 gradio的web端页面格式不对的问题
    • ¥15 求大家看看Nonce如何配置
    • ¥15 Matlab怎么求解含参的二重积分?
    • ¥15 苹果手机突然连不上wifi了?
    • ¥15 cgictest.cgi文件无法访问
    • ¥20 删除和修改功能无法调用