\JShrinkMinifier

Minifier

Usage - Minifier::minify($js); Usage - Minifier::minify($js, $options); Usage - Minifier::minify($js, array('flaggedComments' => false));

Summary

Methods
Properties
Constants
minify()
No public properties found
No constants found
minifyDirectToOutput()
initialize()
loop()
clean()
getChar()
getReal()
processOneLineComments()
processMultiLineComments()
getNext()
saveString()
saveRegex()
isAlphaNumeric()
lock()
unlock()
$input
$index
$a
$b
$c
$options
$stringDelimiters
$defaultOptions
$locks
N/A
No private methods found
No private properties found
N/A

Properties

$input

$input : string

The input javascript to be minified.

Type

string

$index

$index : integer

The location of the character (in the input string) that is next to be processed.

Type

integer

$a

$a : string

The first of the characters currently being looked at.

Type

string

$b

$b : string

The next character being looked at (after a);

Type

string

$c

$c : 

This character is only active when certain look ahead actions take place.

@var string

Type

$options

$options : array

Contains the options for the current minification process.

Type

array

$stringDelimiters

$stringDelimiters : 

These characters are used to define strings.

Type

$defaultOptions

$defaultOptions : array

Contains the default options for minification. This array is merged with the one passed in by the user to create the request specific set of options (stored in the $options attribute).

Type

array

$locks

$locks : array

Contains lock ids which are used to replace certain code patterns and prevent them from being minified

Type

array

Methods

minify()

minify(string  $js, array  $options = array()) : boolean|string

Takes a string containing javascript and removes unneeded characters in order to shrink the code without altering it's functionality.

Parameters

string $js

The raw javascript to be minified

array $options

Various runtime options in an associative array

Throws

\Exception

Returns

boolean|string

minifyDirectToOutput()

minifyDirectToOutput(string  $js, array  $options) 

Processes a javascript string and outputs only the required characters, stripping out all unneeded characters.

Parameters

string $js

The raw javascript to be minified

array $options

Various runtime options in an associative array

initialize()

initialize(string  $js, array  $options) 

Initializes internal variables, normalizes new lines,

Parameters

string $js

The raw javascript to be minified

array $options

Various runtime options in an associative array

loop()

loop() 

The primary action occurs here. This function loops through the input string, outputting anything that's relevant and discarding anything that is not.

clean()

clean() 

Resets attributes that do not need to be stored between requests so that the next request is ready to go. Another reason for this is to make sure the variables are cleared and are not taking up memory.

getChar()

getChar() : string

Returns the next string for processing based off of the current index.

Returns

string

getReal()

getReal() : string

This function gets the next "real" character. It is essentially a wrapper around the getChar function that skips comments. This has significant performance benefits as the skipping is done using native functions (ie, c code) rather than in script php.

Throws

\RuntimeException

Returns

string —

Next 'real' character to be processed.

processOneLineComments()

processOneLineComments(integer  $startIndex) : void

Removed one line comments, with the exception of some very specific types of conditional comments.

Parameters

integer $startIndex

The index point where "getReal" function started

processMultiLineComments()

processMultiLineComments(integer  $startIndex) : void

Skips multiline comments where appropriate, and includes them where needed.

Conditional comments and "license" style blocks are preserved.

Parameters

integer $startIndex

The index point where "getReal" function started

Throws

\RuntimeException

Unclosed comments will throw an error

getNext()

getNext(string  $string) : string|false

Pushes the index ahead to the next instance of the supplied string. If it is found the first character of the string is returned and the index is set to it's position.

Parameters

string $string

Returns

string|false —

Returns the first character of the string or false.

saveString()

saveString() 

When a javascript string is detected this function crawls for the end of it and saves the whole string.

Throws

\RuntimeException

Unclosed strings will throw an error

saveRegex()

saveRegex() 

When a regular expression is detected this function crawls for the end of it and saves the whole regex.

Throws

\RuntimeException

Unclosed regex will throw an error

isAlphaNumeric()

isAlphaNumeric(string  $char) : boolean

Checks to see if a character is alphanumeric.

Parameters

string $char

Just one character

Returns

boolean

lock()

lock(string  $js) : boolean

Replace patterns in the given string and store the replacement

Parameters

string $js

The string to lock

Returns

boolean

unlock()

unlock(string  $js) : boolean

Replace "locks" with the original characters

Parameters

string $js

The string to unlock

Returns

boolean