From fc446fde5be12a4a311793d0f83e44d369aee1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 27 Jun 2006 09:19:21 +0000 Subject: [PATCH] Add var_export compatibility wrapper from PEAR PHP_Compat to make setup.php work on PHP 4.1 (bug #1513007). --- ChangeLog | 3 + libraries/compat/.cvsignore | 1 + libraries/compat/var_export.php | 136 ++++++++++++++++++++++++++++++++ scripts/setup.php | 3 + 4 files changed, 143 insertions(+) create mode 100644 libraries/compat/.cvsignore create mode 100644 libraries/compat/var_export.php diff --git a/ChangeLog b/ChangeLog index 63eee7682..3406cc2f1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,9 @@ $Source$ 2006-06-27 Michal Čihař * libraries/import/csv.php: Fix special case of Excel export with ; at the end (bug #1511046). + * scripts/setup.php, libraries/compat/var_export.php: Add var_export + compatibility wrapper from PEAR PHP_Compat to make setup.php work on PHP + 4.1 (bug #1513007). 2006-06-25 Marc Delisle * libraries/export/pdf.php, libraries/plugin_interface.lib.php, lang/*: diff --git a/libraries/compat/.cvsignore b/libraries/compat/.cvsignore new file mode 100644 index 000000000..1377554eb --- /dev/null +++ b/libraries/compat/.cvsignore @@ -0,0 +1 @@ +*.swp diff --git a/libraries/compat/var_export.php b/libraries/compat/var_export.php new file mode 100644 index 000000000..b15fe8228 --- /dev/null +++ b/libraries/compat/var_export.php @@ -0,0 +1,136 @@ + | +// +----------------------------------------------------------------------+ +// +// $Id: var_export.php,v 1.15 2005/12/05 14:24:27 aidan Exp $ + + +/** + * Replace var_export() + * + * @category PHP + * @package PHP_Compat + * @link http://php.net/function.var_export + * @author Aidan Lister + * @version $Revision: 1.15 $ + * @since PHP 4.2.0 + * @require PHP 4.0.0 (user_error) + */ +if (!function_exists('var_export')) { + function var_export($var, $return = false, $level = 0) + { + // Init + $indent = ' '; + $doublearrow = ' => '; + $lineend = ",\n"; + $stringdelim = '\''; + $newline = "\n"; + $find = array(null, '\\', '\''); + $replace = array('NULL', '\\\\', '\\\''); + $out = ''; + + // Indent + $level++; + for ($i = 1, $previndent = ''; $i < $level; $i++) { + $previndent .= $indent; + } + + // Handle each type + switch (gettype($var)) { + // Array + case 'array': + $out = 'array (' . $newline; + foreach ($var as $key => $value) { + // Key + if (is_string($key)) { + // Make key safe + for ($i = 0, $c = count($find); $i < $c; $i++) { + $var = str_replace($find[$i], $replace[$i], $var); + } + $key = $stringdelim . $key . $stringdelim; + } + + // Value + if (is_array($value)) { + $export = var_export($value, true, $level); + $value = $newline . $previndent . $indent . $export; + } else { + $value = var_export($value, true, $level); + } + + // Piece line together + $out .= $previndent . $indent . $key . $doublearrow . $value . $lineend; + } + + // End string + $out .= $previndent . ')'; + break; + + // String + case 'string': + // Make the string safe + for ($i = 0, $c = count($find); $i < $c; $i++) { + $var = str_replace($find[$i], $replace[$i], $var); + } + $out = $stringdelim . $var . $stringdelim; + break; + + // Number + case 'integer': + case 'double': + $out = (string) $var; + break; + + // Boolean + case 'boolean': + $out = $var ? 'true' : 'false'; + break; + + // NULLs + case 'NULL': + case 'resource': + $out = 'NULL'; + break; + + // Objects + case 'object': + // Start the object export + $out = $newline . $previndent . 'class ' . get_class($var) . ' {' . $newline; + + // Export the object vars + foreach (get_object_vars($var) as $key => $val) { + $out .= $previndent . ' var $' . $key . ' = '; + if (is_array($val)) { + $export = var_export($val, true, $level); + $out .= $newline . $previndent . $indent . $export . ';' . $newline; + } else { + $out .= var_export($val, true, $level) . ';' . $newline; + } + } + $out .= $previndent . '}'; + break; + } + + // Method of output + if ($return === true) { + return $out; + } else { + echo $out; + } + } +} + +?> diff --git a/scripts/setup.php b/scripts/setup.php index 527dc2d57..6fbf7ccb6 100644 --- a/scripts/setup.php +++ b/scripts/setup.php @@ -9,6 +9,9 @@ define( 'PMA_MINIMUM_COMMON', TRUE ); chdir('..'); require_once('./libraries/common.lib.php'); +// var_export for older PHP +require_once('./libraries/compat/var_export.php'); + // Grab configuration defaults $PMA_Config = new PMA_Config();