Packer
in package
The packer class is a PHP version of Dean Edwards's Js minifier and obfuscator originaly ported to PHP by Nicolas Martin and revised by us for php 8.4
used by helphp\utils\minify.php to compact all js scripts of your instance before going to production usage exemple :
$js_str='some js';
//the 10 parameter offer the maximum compatibily with all the navigators
$packer = new Packer($js_str, '10');
$packed_js = $packer->pack(); //save the js file writeUTF8File($target.'jsgz/all.js', $packed_js);
Table of Contents
Constants
- IGNORE = '$1'
- JSFUNCTION_decodeBody = ' if (!\'\'.replace(/^/, String)) { // decode all the values we need while ($count--) { $decode[$encode($count)] = $keywords[$count] || $encode($count); } // global replacement function $keywords = [function ($encoded) {return $decode[$encoded]}]; // generic match $encode = function () {return \'\\\\w+\'}; // reset the loop counter - we are now doing a global replace $count = 1; } '
- JSFUNCTION_encode10 = 'function($charCode) { return $charCode; }'
- JSFUNCTION_encode36 = 'function($charCode) { return $charCode.toString(36); }'
- JSFUNCTION_encode62 = 'function($charCode) { return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) + (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36)); }'
- JSFUNCTION_encode95 = 'function($charCode) { return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) + String.fromCharCode($charCode % _encoding + 161); }'
- JSFUNCTION_unpack = 'function($packed, $ascii, $count, $keywords, $encode, $decode) { while ($count--) { if ($keywords[$count]) { $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); } } return $packed; }'
Methods
- __construct() : mixed
- pack() : mixed
Constants
IGNORE
public
mixed
IGNORE
= '$1'
JSFUNCTION_decodeBody
public
mixed
JSFUNCTION_decodeBody
= ' if (!\'\'.replace(/^/, String)) {
// decode all the values we need
while ($count--) {
$decode[$encode($count)] = $keywords[$count] || $encode($count);
}
// global replacement function
$keywords = [function ($encoded) {return $decode[$encoded]}];
// generic match
$encode = function () {return \'\\\\w+\'};
// reset the loop counter - we are now doing a global replace
$count = 1;
}
'
JSFUNCTION_encode10
public
mixed
JSFUNCTION_encode10
= 'function($charCode) {
return $charCode;
}'
JSFUNCTION_encode36
public
mixed
JSFUNCTION_encode36
= 'function($charCode) {
return $charCode.toString(36);
}'
JSFUNCTION_encode62
public
mixed
JSFUNCTION_encode62
= 'function($charCode) {
return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) +
(($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36));
}'
JSFUNCTION_encode95
public
mixed
JSFUNCTION_encode95
= 'function($charCode) {
return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) +
String.fromCharCode($charCode % _encoding + 161);
}'
JSFUNCTION_unpack
public
mixed
JSFUNCTION_unpack
= 'function($packed, $ascii, $count, $keywords, $encode, $decode) {
while ($count--) {
if ($keywords[$count]) {
$packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]);
}
}
return $packed;
}'
Methods
__construct()
public
__construct(mixed $_script[, mixed $_encoding = 62 ][, mixed $_fastDecode = true ][, mixed $_specialChars = false ]) : mixed
Parameters
- $_script : mixed
- $_encoding : mixed = 62
- $_fastDecode : mixed = true
- $_specialChars : mixed = false
pack()
public
pack() : mixed