Remove function minification for performance and customization
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@912 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
68ae7a597d
commit
90a6bd8d4b
|
@ -365,7 +365,6 @@ function email_header($header) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function call_adminer($method, $default, $arg1 = null, $arg2 = null, $arg3 = null) {
|
function call_adminer($method, $default, $arg1 = null, $arg2 = null, $arg3 = null) {
|
||||||
// maintains original method name in minification
|
|
||||||
if (method_exists('Adminer', $method)) { // user defined class
|
if (method_exists('Adminer', $method)) { // user defined class
|
||||||
// can use func_get_args() and call_user_func_array()
|
// can use func_get_args() and call_user_func_array()
|
||||||
return Adminer::$method($arg1, $arg2, $arg3);
|
return Adminer::$method($arg1, $arg2, $arg3);
|
||||||
|
|
|
@ -24,63 +24,13 @@ if (extension_loaded("mysqli")) {
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$row = $result->_result->fetch_array();
|
$row = $result->fetch_array();
|
||||||
return $row[$field];
|
return $row[$field];
|
||||||
}
|
}
|
||||||
|
|
||||||
function quote($string) {
|
function quote($string) {
|
||||||
return "'" . parent::escape_string($string) . "'";
|
return "'" . $this->escape_string($string) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
// minification compatibility start
|
|
||||||
function select_db($database) {
|
|
||||||
return parent::select_db($database);
|
|
||||||
}
|
|
||||||
|
|
||||||
function query($query) {
|
|
||||||
// result is packed in envelope object to allow minification
|
|
||||||
$result = parent::query($query);
|
|
||||||
return (is_object($result) ? new Min_Result($result) : $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function multi_query($query) {
|
|
||||||
return parent::multi_query($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
function store_result() {
|
|
||||||
$result = parent::store_result();
|
|
||||||
return (is_object($result) ? new Min_Result($result) : $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
function next_result() {
|
|
||||||
return parent::next_result();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Min_Result {
|
|
||||||
var $_result, $num_rows;
|
|
||||||
|
|
||||||
function __construct($result) {
|
|
||||||
$this->_result = $result;
|
|
||||||
$this->num_rows = $result->num_rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetch_assoc() {
|
|
||||||
return $this->_result->fetch_assoc();
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetch_row() {
|
|
||||||
return $this->_result->fetch_row();
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetch_field() {
|
|
||||||
return $this->_result->fetch_field();
|
|
||||||
}
|
|
||||||
|
|
||||||
function free() {
|
|
||||||
return $this->_result->free();
|
|
||||||
}
|
|
||||||
// minification compatibility end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif (extension_loaded("mysql")) {
|
} elseif (extension_loaded("mysql")) {
|
||||||
|
|
|
@ -381,7 +381,7 @@ if (!$columns) {
|
||||||
}
|
}
|
||||||
echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
|
echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
|
||||||
|
|
||||||
adminer_select_extra_display(array_filter($email_fields)); //! should use strlen but compile.php doesn't support array_filter
|
adminer_select_extra_display(array_filter($email_fields, 'strlen'));
|
||||||
|
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
}
|
}
|
||||||
|
|
27
compile.php
27
compile.php
|
@ -80,20 +80,12 @@ function short_identifier($number, $chars) {
|
||||||
function php_shrink($input) {
|
function php_shrink($input) {
|
||||||
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
||||||
static $short_variables = array();
|
static $short_variables = array();
|
||||||
static $short_functions = array();
|
|
||||||
$shortening = true;
|
$shortening = true;
|
||||||
$special_functions = array_flip(array('Min_DB', 'Min_Result', '__construct'));
|
|
||||||
$defined_functions = array();
|
|
||||||
$tokens = token_get_all($input);
|
$tokens = token_get_all($input);
|
||||||
|
|
||||||
foreach ($tokens as $i => $token) {
|
foreach ($tokens as $i => $token) {
|
||||||
if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
||||||
$short_variables[$token[1]]++;
|
$short_variables[$token[1]]++;
|
||||||
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !isset($special_functions[$token[1]])) {
|
|
||||||
$short_functions[$token[1]]++;
|
|
||||||
if ($tokens[$i-2][0] === T_FUNCTION) {
|
|
||||||
$defined_functions[$token[1]] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,16 +93,6 @@ function php_shrink($input) {
|
||||||
foreach (array_keys($short_variables) as $number => $key) {
|
foreach (array_keys($short_variables) as $number => $key) {
|
||||||
$short_variables[$key] = short_identifier($number, implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z'))); // could use also numbers and \x7f-\xff
|
$short_variables[$key] = short_identifier($number, implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z'))); // could use also numbers and \x7f-\xff
|
||||||
}
|
}
|
||||||
arsort($short_functions);
|
|
||||||
$number = 0;
|
|
||||||
foreach ($short_functions as $key => $val) {
|
|
||||||
if (isset($defined_functions[$key])) {
|
|
||||||
do {
|
|
||||||
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z'))); // _ not used to not collide with gettext()
|
|
||||||
$number++;
|
|
||||||
} while (isset($short_functions[$short_functions[$key]])); // don't overwrite existing functions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
|
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
|
||||||
$space = '';
|
$space = '';
|
||||||
|
@ -145,15 +127,6 @@ function php_shrink($input) {
|
||||||
}
|
}
|
||||||
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
||||||
$token[1] = '$' . $short_variables[$token[1]];
|
$token[1] = '$' . $short_variables[$token[1]];
|
||||||
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && isset($defined_functions[$token[1]])
|
|
||||||
&& $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && $tokens[$i-2][1] !== '_result' // don't substitute parent methods - used to link PHP methods only
|
|
||||||
) {
|
|
||||||
$token[1] = $short_functions[$token[1]];
|
|
||||||
} elseif ($token[0] == T_CONSTANT_ENCAPSED_STRING
|
|
||||||
&& (($tokens[$i-1] === '(' && in_array($tokens[$i-2][1], array('array_map', 'set_exception_handler'), true)) || $token[1] == "'normalize_enum'")
|
|
||||||
&& isset($defined_functions[substr($token[1], 1, -1)])
|
|
||||||
) { // minify callback functions too
|
|
||||||
$token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
|
|
||||||
}
|
}
|
||||||
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
|
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
|
||||||
$space = '';
|
$space = '';
|
||||||
|
|
Loading…
Reference in a new issue