jssource/Minifier.php
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
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
string
$a= ''''
The first of the characters currently being looked at.
''
Details- Type
- string
$c= ''
This character is only active when certain look ahead actions take place.
@var string
- Type
- n/a
array
$defaultOptions= 'array('flaggedComments' => true)'
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).
array('flaggedComments' => true)
Details- Type
- array
int
$index= '0'
The location of the character (in the input string) that is next to be processed.
0
Details- Type
- int
$jshrink= ''
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.
- Type
- n/a
Methods
breakdownScript(
string $js, array $currentOptions
)
:
void
Processes a javascript string and outputs only the required characters, stripping out all unneeded characters.
Name | Type | Description |
---|---|---|
$js | string | The raw javascript to be minified |
$currentOptions | array | Various runtime options in an associative array |
clean(
)
:
void
Resets attributes that do not need to be stored between requests so that the next request is ready to go.
getChar(
)
:
string
Returns the next string for processing based off of the current index.
Type | Description |
---|---|
string |
getNext(
$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.
Name | Type | Description |
---|---|---|
$string |
Type | Description |
---|---|
string | false | Returns the first character of the string if found, false otherwise. |
getReal(
)
:
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.
Type | Description |
---|---|
string | Next 'real' character to be processed. |
isAlphaNumeric(
$char
)
:
bool
Checks to see if a character is alphanumeric.
Name | Type | Description |
---|---|---|
$char |
Type | Description |
---|---|
bool |
minify(
$js, $options
=
array()
)
:
void
Minifier::minify takes a string containing javascript and removes unneeded characters in order to shrink the code without altering it's functionality.
Name | Type | Description |
---|---|---|
$js | ||
$options |
saveRegex(
)
:
void
When a regular expression is detected this funcion crawls for the end of it and saves the whole regex.