Classe: SourceMap - X-Ref
SourceMap class,
reads a generic language source code and returns its map.
______________________________________________________________
The SourceMap goals is to create a map of a generic script/program language.
The getMap method returns an array/list of arrays/dictionary/objects
of source map using delimeters variable to map correctly:
- multi line comments
- single line comments
- double quoted strings
- single quoted strings
- pure code
- everything else (for example regexp [/re/] with javascript), just adding a correct delimeter
--------------------------------------------------------------
What about the delimeter
It's an array/list of arrays/dictionary/obects with some properties to find what you're looking for.
parameters are:
- name, the name of the delimeter (i.e. "doublequote")
- start, one or mode chars to find as start delimeter (i.e. " for double quoted string)
- end, one or mode chars to find as end delimeter (i.e. " for double quoted string) [end should be an array/list too]
optional parameters are:
- noslash, if true find the end of the delimeter only if last char is not slashed (i.e. "string\"test" find " after test)
- match, if choosed language has regexp, verify if string from start to end matches used regexp (i.e. /^\/[^\n\r]+\/$/ for JavaScript regexp)
If end parameter is an array, match and noslash are not supported (i.e. ["\n", "\r"] for end delimeter of a single line comment)
--------------------------------------------------------------
What about SourceMap usage
It should be a good solution to create sintax highlighter, parser,
verifier or some other source code parsing procedure
--------------------------------------------------------------
What about SourceMap performance script/languages
I've created different version of this class to test each script/program language performance too.
Python with or without Psyco is actually the faster parser.
However with this PHP version this class has mapped "dojo.js.uncompressed.js" file (about 211Kb) in less than 0.5 second.
Test has been done with embed class and PHP as module, any accelerator was used for this PHP test.
--------------------------------------------------------------
getMap(&$source, &$delimeters)
X-Ref
|
public method
getMap(&$source:string, &$delimeters:array):array
Maps the source code using $delimeters rules and returns map as an array
NOTE: read comments to know more about map and delimeter
param: string generic source code
param: array array with nested array with code rules
|
Classe: JavaScriptCompressor - X-Ref
JavaScriptCompressor class,
removes comments or pack JavaScript source[s] code.
______________________________________________________________
JavaScriptCompressor (just 2 public methods)
|
|________ getClean(jsSource:mixed):string
| returns one or more JavaScript code without comments,
| by default removes some spaces too
|
|________ getPacked(jsSource:mixed):string
returns one or more JavaScript code packed,
using getClean and obfuscating output
--------------------------------------------------------------
Note about $jsSource input varible:
this var should be a string (i.e. $jsSource = file_get_contents("myFile.js");)
should be an array of strings (i.e. array(file_get_contents("1.js"), file_get_contents("2.js"), ... ))
should be an array with 1 or 2 keys:
(i.e. array('code'=>file_get_contents("mySource.js")))
(i.e. array('code'=>file_get_contents("mySource.js"), 'name'=>'mySource'))
... and should be an array of arrays created with theese rules
array(
file_get_contents("secret.js"),
array('code'=>$anotherJS),
array('code'=>$myJSapplication, 'name'=>'JSApplication V 1.0')
)
The name used on dedicated key, will be write on parsed source header
--------------------------------------------------------------
Note about returned strings:
Your browser should wrap very long strings, then don't use
cut and paste from your browser, save output into your database or directly
in a file or print them only inside <script> and </script> tags
--------------------------------------------------------------
Note about parser performance:
With pure PHP embed code this class should be slow and not really safe
for your server performance then don't parse JavaScript runtime for each
file you need and create some "parsed" caching system
(at least while i've not created a compiled version of theese class functions).
Here there's a caching system example: http://www.phpclasses.org/browse/package/3158.html
--------------------------------------------------------------
Note about JavaScript packed compatibility:
To be sure about compatibility include before every script JSL Library:
http://www.devpro.it/JSL/
JSL library add some features for old or buggy browsers, one of
those functions is String.replace with function as second argument,
used by JavaScript generated packed code to rebuild original code.
Remember that KDE 3.5, Safari and IE5 will not work correctly with packed version
if you'll not include JSL.
--------------------------------------------------------------
getClean($jsSource)
X-Ref
|
public method
getClean(mixed [, bool]):string
compress JavaScript removing comments and somespaces (on by default)
param: mixed view example and notes on class comments
|
getPacked($jsSource)
X-Ref
|
public method
getPacked(mixed):string
compress JavaScript replaceing words and removing comments and some spaces
param: mixed view example and notes on class comments
|