PHP Class Minify_JS_ClosureCompiler, minify

Show file Open project: mrclay/minify Class Usage Examples

Protected Properties

Property Type Description
$additionalOptions string[] Additional options to pass to the compiler service
$fallbackMinifier Function to minify JS if service fails. Default is JSMin
$maxBytes integer The maximum JS size that can be sent to the compiler server in bytes
$serviceUrl string

Public Methods

Method Description
__construct ( array $options = [] )
min ( string $js ) : string Call the service to perform the minification
minify ( string $js, array $options = [] ) : string Minify JavaScript code via HTTP request to a Closure Compiler API

Protected Methods

Method Description
buildPostBody ( string $js, boolean $returnErrors = false ) : string Build a POST request body
getResponse ( string $postBody ) : string Get the response for a given POST body

Method Details

__construct() public method

public __construct ( array $options = [] )
$options array Options with keys available below: fallbackFunc : (callable) function to minify if service unavailable. Default is JSMin. compilerUrl : (string) URL to closure compiler server maxBytes : (int) The maximum amount of bytes to be sent as js_code in the POST request. Defaults to 200000. additionalParams : (string[]) Additional parameters to pass to the compiler server. Can be anything named in https://developers.google.com/closure/compiler/docs/api-ref except for js_code and output_info

buildPostBody() protected method

Build a POST request body
protected buildPostBody ( string $js, boolean $returnErrors = false ) : string
$js string JavaScript code
$returnErrors boolean
return string

getResponse() protected method

Get the response for a given POST body
protected getResponse ( string $postBody ) : string
$postBody string
return string

min() public method

Call the service to perform the minification
public min ( string $js ) : string
$js string JavaScript code
return string

minify() public static method

Minify JavaScript code via HTTP request to a Closure Compiler API
public static minify ( string $js, array $options = [] ) : string
$js string input code
$options array Options passed to __construct(). @see __construct
return string

Property Details

$additionalOptions protected property

Additional options to pass to the compiler service
protected string[] $additionalOptions
return string[]

$fallbackMinifier protected property

Function to minify JS if service fails. Default is JSMin
protected $fallbackMinifier

$maxBytes protected property

The maximum JS size that can be sent to the compiler server in bytes
protected int $maxBytes
return integer

$serviceUrl protected property

protected string $serviceUrl
return string