Git Product home page Git Product logo

php-closure-compiler's Introduction

##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.

##Installation

You can install the library with composer or manually.

Composer

Step 1. Edit your composer.json:

{
    "require": {
        "tureki/phpcc": ">=1.0.5"
    }
}

Step 2. Install it:

$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install

Manually From Release

Step 1. Download the latest release

Step 2. Include the library:

require_once '[path to phpcc]/phpcc.php';

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.php';

$phpcc = new tureki\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);

Todo

a. Add Unit Test b. Integrate CI

Authors

tureki

Copyright and License

Copyright 2013 tureki, under MIT License.

php-closure-compiler's People

Contributors

tureki avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.