Skip to content

A PHP Library to use Google Closure Compiler compress Javascript

Notifications You must be signed in to change notification settings

tureki/php-closure-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##PHP Closure Compiler

phpcc is a PHP Library to use Google Closure Compiler compress Javascript. You can view information about Google Closure Compiler on this link.

How to use

Download phpcc Library. and then require phpcc.class.php in your .php file. You can test sample.php in samples folder.

require '../src/phpcc.class.php';

$phpcc = new PhpCc(array(
	'java_file'    => 'YOUR JAVA FILE PATH',
	'jar_file'     => '../src/compiler/compiler.jar', 
	'output_path'  => './output/',
	'optimization' => 'SIMPLE_OPTIMIZATIONS'
));

java_file is system java execute file path.

Example:
-   Linux:"/usr/lib/jvm/jre-1.6.0/bin/java"
-   Window7:"C:\Program Files (x86)\Java\jre6\bin\java"

jar_file is Google Closure Compiler jar file. Your can download latest version on this link


After setting. use help() method to test phpcc.

print_r($phpcc->help());

How to compress

Add jQuery file and combined compression to one file.

$ary_result = $phpcc
                ->add("js/jquery-1.10.2.js")
                ->add("js/1.9/jquery-1.9.1.js")
                ->exec("all.js");
print_r($ary_result);

Set Directory path find .js file and combined compression to one file.

$ary_result = $phpcc
                ->setDir("./js")
                ->exec("all.js");
print_r($ary_result);

Use single() can individual compression.

$ary_result = $phpcc
                ->add("js/jquery-1.10.2.js")
                ->add("js/1.9/jquery-1.9.1.js")
                ->single()
                ->exec();
print_r($ary_result);
$ary_result = $phpcc
                ->setDir("./js")
                ->single()
                ->exec();
print_r($ary_result);

You can also mixed.

$ary_result = $phpcc
                ->add("js/jquery-1.10.2.js")
                ->add("js/1.9/jquery-1.9.1.js")
                ->setDir("./js")
                ->single()
                ->exec();
print_r($ary_result);

You can use param() add Closure Compiler command param.

$ary_result = $phpcc
                ->add("js/jquery-1.10.2.js")
                ->param("--angular_pass")
                ->param("--formatting","PRETTY_PRINT")
                ->exec("all.js");
print_r($ary_result);

Authors

tureki

Copyright and license

Copyright 2013 tureki, under the Apache 2.0 license.

About

A PHP Library to use Google Closure Compiler compress Javascript

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages