diff --git a/common/framework/config.php b/common/framework/config.php index 93f1eb265..0d1ab7ef3 100644 --- a/common/framework/config.php +++ b/common/framework/config.php @@ -136,7 +136,7 @@ class Config } // Save the main config file. - $buff = 'ftp_info); $warning = '// DO NOT EDIT THIS FILE. CHANGES WILL NOT BE APPLIED.' . "\n" . '// TO CHANGE RHYMIX SYSTEM CONFIGURATION, EDIT config.php INSTEAD.'; - $buff = '\s+array\(\n/', "=> array(\n", $value); + $value = preg_replace('/array\(\s*\n\s*\)/', 'array()', $value); + $value = preg_replace_callback('/\n(\x20+)/', function($m) { + return "\n" . str_repeat("\t", intval(strlen($m[1]) / 2)); + }, $value); + $value = preg_replace('/\n(\t+)[0-9]+ => /', "\n\$1", $value); + return $value; + } + else + { + return var_export($value, true); + } + } } diff --git a/common/framework/debug.php b/common/framework/debug.php index 81e4326ff..04836b6b5 100644 --- a/common/framework/debug.php +++ b/common/framework/debug.php @@ -274,7 +274,7 @@ class Debug if (config('debug.write_error_log') === 'all' && self::isEnabledForCurrentUser()) { $log_entry = str_replace("\0", '', sprintf('Rhymix Debug: %s in %s on line %d', - var_export_clean($message), $entry->file, $entry->line)); + var_export($message, true), $entry->file, $entry->line)); error_log($log_entry); } } diff --git a/common/framework/parsers/langparser.php b/common/framework/parsers/langparser.php index 8d667ba44..b2185ce38 100644 --- a/common/framework/parsers/langparser.php +++ b/common/framework/parsers/langparser.php @@ -82,18 +82,18 @@ class LangParser { foreach ($subvalue as $subsubkey => $subsubvalue) { - $buff .= '$lang->' . $key . "['$subkey']['$subsubkey']" . ' = ' . var_export_clean($subsubvalue) . ";\n"; + $buff .= '$lang->' . $key . "['$subkey']['$subsubkey']" . ' = ' . var_export($subsubvalue, true) . ";\n"; } } else { - $buff .= '$lang->' . $key . "['$subkey']" . ' = ' . var_export_clean($subvalue) . ";\n"; + $buff .= '$lang->' . $key . "['$subkey']" . ' = ' . var_export($subvalue, true) . ";\n"; } } } else { - $buff .= '$lang->' . $key . ' = ' . var_export_clean($value) . ";\n"; + $buff .= '$lang->' . $key . ' = ' . var_export($value, true) . ";\n"; } } Storage::write($output_filename, $buff); diff --git a/common/framework/storage.php b/common/framework/storage.php index 95fca7db1..4ac59397d 100644 --- a/common/framework/storage.php +++ b/common/framework/storage.php @@ -337,7 +337,7 @@ class Storage { $comment = "/* $comment */\n"; } - return self::write($filename, '<' . '?php ' . $comment . 'return ' . var_export_clean($data) . ';'); + return self::write($filename, '<' . '?php ' . $comment . 'return unserialize(' . var_export(serialize($data), true) . ');'); } /** diff --git a/common/functions.php b/common/functions.php index 7e6da87a6..078c280e5 100644 --- a/common/functions.php +++ b/common/functions.php @@ -409,22 +409,6 @@ function url2path($url) return Rhymix\Framework\URL::toServerPath($url); } -/** - * This function fixes some of the issues with var_export() so that the result executes cleanly. - * - * @param mixed $var - * @return string - */ -function var_export_clean($var) -{ - $result = var_export($var, true); - if (version_compare(PHP_VERSION, '7.3', '<')) - { - $result = preg_replace('/stdClass::__set_state\((?=array\(\n)/', '(object)(', $result); - } - return $result; -} - /** * Convert hexadecimal color codes to an array of R, G, B values. * This function can handle both 6-digit and 3-digit notations, optionally prefixed with '#'. diff --git a/common/tpl/debug_comment.html b/common/tpl/debug_comment.html index b4f6d60b3..e3213c2ba 100644 --- a/common/tpl/debug_comment.html +++ b/common/tpl/debug_comment.html @@ -43,7 +43,7 @@ Debug Entries { if (is_scalar($entry->message)) { - $entry->message = var_export_clean($entry->message); + $entry->message = var_export($entry->message, true); } else { diff --git a/tests/unit/framework/ConfigTest.php b/tests/unit/framework/ConfigTest.php index 52d372aa7..b9ef136d2 100644 --- a/tests/unit/framework/ConfigTest.php +++ b/tests/unit/framework/ConfigTest.php @@ -18,5 +18,9 @@ class ConfigTest extends \Codeception\TestCase\Test Rhymix\Framework\Config::set('foo.bar', $rand = mt_rand()); $this->assertEquals(array('bar' => $rand), Rhymix\Framework\Config::get('foo')); $this->assertEquals($rand, Rhymix\Framework\Config::get('foo.bar')); + + $var = array('foo' => 'bar'); + $serialized = "array(\n\t'foo' => 'bar',\n)"; + $this->assertEquals($serialized, Rhymix\Framework\Config::serialize($var)); } } diff --git a/tests/unit/functions/FunctionsTest.php b/tests/unit/functions/FunctionsTest.php index 745692a90..d2ee628c0 100644 --- a/tests/unit/functions/FunctionsTest.php +++ b/tests/unit/functions/FunctionsTest.php @@ -103,21 +103,6 @@ class FunctionsTest extends \Codeception\TestCase\Test $this->assertEquals('Rhymix ^~', base64_decode_urlsafe('Umh5bWl4IF5-')); } - public function testVarExportClean() - { - $obj = new stdClass; - $obj->foo = 42; - $obj->bar = 7; - if (version_compare(PHP_VERSION, '7.3', '<')) - { - $this->assertEquals("(object)(array(\n 'foo' => 42,\n 'bar' => 7,\n))", var_export_clean($obj)); - } - else - { - $this->assertEquals("(object) array(\n 'foo' => 42,\n 'bar' => 7,\n)", var_export_clean($obj)); - } - } - public function testHex2Rgb2Hex() { $this->assertEquals(array(128, 128, 128), hex2rgb('808080'));