\Minifier

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
$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 : int

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

Type

int

$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

$options

$options : array

Contains the options for the current minification process.

Type

array

$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()) : bool|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

bool|string —

minifyDirectToOutput()

minifyDirectToOutput(string  $js, array  $options) : mixed

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

Returns

mixed —

initialize()

initialize(string  $js, array  $options) : mixed

Initializes internal variables, normalizes new lines,

Parameters

string $js

The raw javascript to be minified

array $options

Various runtime options in an associative array

Returns

mixed —

loop()

loop() : mixed

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

Returns

mixed —

clean()

clean() : mixed

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.

Returns

mixed —

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(int  $startIndex) : string

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

Parameters

int $startIndex

The index point where "getReal" function started

Returns

string —

processMultiLineComments()

processMultiLineComments(int  $startIndex) : bool|string

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

Conditional comments and "license" style blocks are preserved.

Parameters

int $startIndex

The index point where "getReal" function started

Throws

\RuntimeException

Unclosed comments will throw an error

Returns

bool|string —

False if there's no character

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() : mixed

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

Returns

mixed —

saveRegex()

saveRegex() : mixed

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

Returns

mixed —

isAlphaNumeric()

isAlphaNumeric(string  $char) : bool

Checks to see if a character is alphanumeric.

Parameters

string $char

Just one character

Returns

bool —

lock()

lock(string  $js) : bool

Replace patterns in the given string and store the replacement

Parameters

string $js

The string to lock

Returns

bool —

unlock()

unlock(string  $js) : bool

Replace "locks" with the original characters

Parameters

string $js

The string to unlock

Returns

bool —