jssource/Minifier.php

Show: inherited
Table of Contents

JShrink

Copyright (c) 2009-2012, Robert Hafner tedivm@tedivm.com. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of Robert Hafner nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Robert Hafner  
Copyright
2009-2012 Robert Hafner  
License
BSD License  
Link
https://github.com/tedivm/JShrink  
Package
JShrink  
Version
Release: 0.4  

\Minifier

Package: JShrink

Minifier

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

Author
Robert Hafner  
License
BSD License  
Version
0.4  

Properties

Propertyprotectedstring  $a= ''''

The first of the characters currently being looked at.

Default value''Details
Type
string
Propertyprotectedstring  $b= ''''

The next character being looked at (after a);

Default value''Details
Type
string
Propertyprotected  $c= ''

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

@var string

Details
Type
n/a
Propertyprotectedarray  $defaultOptions= 'array('flaggedComments' => true)'
static

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

Default valuearray('flaggedComments' => true)Details
Type
array
Propertyprotectedint  $index= '0'

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

Default value0Details
Type
int
Propertyprotectedstring  $input= ''

The input javascript to be minified.

Details
Type
string
Propertyprotected  $jshrink= ''
static

Contains a copy of the JShrink object used to run minification. This is only used internally, and is only stored for performance reasons. There is no internal data shared between minification requests.

Details
Type
n/a
Propertyprotectedarray  $options= ''

Contains the options for the current minification process.

Details
Type
array

Methods

methodprotectedbreakdownScript( string $js, array $currentOptions ) : void

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

Parameters
Name Type Description
$js string

The raw javascript to be minified

$currentOptions array

Various runtime options in an associative array

methodprotectedclean( ) : void

Resets attributes that do not need to be stored between requests so that the next request is ready to go.

methodprotectedgetChar( ) : string

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

Returns
Type Description
string
methodprotectedgetNext(  $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.

Parameters
Name Type Description
$string
Returns
Type Description
string | false Returns the first character of the string if found, false otherwise.
methodprotectedgetReal( ) : string

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

Returns
Type Description
string Next 'real' character to be processed.
methodprotectedisAlphaNumeric(  $char ) : bool
static

Checks to see if a character is alphanumeric.

Parameters
Name Type Description
$char
Returns
Type Description
bool
methodpublicminify(  $js,  $options = array() ) : void
static

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

Parameters
Name Type Description
$js
$options
methodprotectedsaveRegex( ) : void

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

methodprotectedsaveString( ) : void

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

Documentation was generated by DocBlox 0.18.1.