|
| 1 | +##PHP Closure Compiler |
| 2 | +== |
| 3 | +**PHPCC** is a PHP Library to use Google Closure Compiler compress Javascript. |
| 4 | +You can view information about Google Closure Compiler on this [link](https://developers.google.com/closure/compiler/). |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +### How to use |
| 9 | + |
| 10 | +Download **phpcc** Library. and then include <code>phpcc.inc</code> in your <code>.php</code> file. you can test <code>sample.php</code>. |
| 11 | + |
| 12 | +<pre> |
| 13 | +include 'src/phpcc.inc'; |
| 14 | + |
| 15 | +$phpcc = new phpcc(array( |
| 16 | + 'java_file' => 'YOUR JAVA FILE PATH', |
| 17 | + 'jar_file' => 'src/compiler/compiler.jar', |
| 18 | + 'output_path' => './output/', |
| 19 | + 'optimization' => 'SIMPLE_OPTIMIZATIONS' |
| 20 | +)); |
| 21 | +</pre> |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +---- |
| 26 | + |
| 27 | +<code>java_file</code> is system java execute file path. |
| 28 | +<pre> |
| 29 | +Example: |
| 30 | +- Linux:"/usr/lib/jvm/jre-1.6.0/bin/java" |
| 31 | +- Window7:"C:\Program Files (x86)\Java\jre6\bin\java" |
| 32 | +</pre> |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +---- |
| 38 | + |
| 39 | +<code>jar_file</code> is Google Closure Compiler jar file. Your can download latest version on this [link](http://code.google.com/p/closure-compiler/wiki/BinaryDownloads) |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +---- |
| 45 | + |
| 46 | +After setting. use <code>help()</code> method to test **phpcc**. |
| 47 | +<pre> |
| 48 | +print_r($phpcc->help()); |
| 49 | +</pre> |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +### How to compress |
| 54 | + |
| 55 | +Add jQuery file and combined compression to one file. |
| 56 | +<pre> |
| 57 | +$ary_result = $phpcc |
| 58 | + ->add("js/jquery-1.10.2.js") |
| 59 | + ->add("js/1.9/jquery-1.9.1.js") |
| 60 | + ->exec("all.js"); |
| 61 | +print_r($ary_result); |
| 62 | +</pre> |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +---- |
| 67 | + |
| 68 | +Set Directory path find <code>.js</code> file and combined compression to one file. |
| 69 | +<pre> |
| 70 | +$ary_result = $phpcc |
| 71 | + ->setDir("./js") |
| 72 | + ->exec("all.js"); |
| 73 | +print_r($ary_result); |
| 74 | +</pre> |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +---- |
| 79 | + |
| 80 | +use <code>single()</code> can individual compression. |
| 81 | +<pre> |
| 82 | +$ary_result = $phpcc |
| 83 | + ->add("js/jquery-1.10.2.js") |
| 84 | + ->add("js/1.9/jquery-1.9.1.js") |
| 85 | + ->single() |
| 86 | + ->exec(); |
| 87 | +print_r($ary_result); |
| 88 | +</pre> |
| 89 | +<pre> |
| 90 | +$ary_result = $phpcc |
| 91 | + ->setDir("./js") |
| 92 | + ->single() |
| 93 | + ->exec(); |
| 94 | +print_r($ary_result); |
| 95 | +</pre> |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +---- |
| 100 | + |
| 101 | +you can also mixed. |
| 102 | +<pre> |
| 103 | +$ary_result = $phpcc |
| 104 | + ->add("js/jquery-1.10.2.js") |
| 105 | + ->add("js/1.9/jquery-1.9.1.js") |
| 106 | + ->setDir("./js") |
| 107 | + ->single() |
| 108 | + ->exec(); |
| 109 | +print_r($ary_result); |
| 110 | +</pre> |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +---- |
| 115 | + |
| 116 | +You can use <code>param()</code> add Closure Compiler command param. |
| 117 | +<pre> |
| 118 | +$ary_result = $phpcc |
| 119 | + ->add("js/jquery-1.10.2.js") |
| 120 | + ->param("--angular_pass") |
| 121 | + ->param("--formatting","PRETTY_PRINT") |
| 122 | + ->exec("all.js"); |
| 123 | +print_r($ary_result); |
| 124 | +</pre> |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +### Authors |
| 129 | + |
| 130 | +**tureki** |
| 131 | + |
| 132 | ++ [http://github.com/tureki](http://github.com/tureki) |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +### Copyright and license |
| 137 | + |
| 138 | +Copyright 2013 tureki, under [the Apache 2.0 license](LICENSE). |
0 commit comments