mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Revert "Fix var_export() not working for stdClass in PHP < 7.3"
This reverts commit 3f7f802585.
This commit is contained in:
parent
7e48c4989e
commit
7b9fe8f7f2
8 changed files with 43 additions and 40 deletions
|
|
@ -136,7 +136,7 @@ class Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the main config file.
|
// Save the main config file.
|
||||||
$buff = '<?php' . "\n" . '// Rhymix System Configuration' . "\n" . 'return ' . var_export_clean(self::$_config) . ';' . "\n";
|
$buff = '<?php' . "\n" . '// Rhymix System Configuration' . "\n" . 'return ' . self::serialize(self::$_config) . ';' . "\n";
|
||||||
$result = Storage::write(\RX_BASEDIR . self::$config_filename, $buff) ? true : false;
|
$result = Storage::write(\RX_BASEDIR . self::$config_filename, $buff) ? true : false;
|
||||||
|
|
||||||
// Save XE-compatible config files.
|
// Save XE-compatible config files.
|
||||||
|
|
@ -145,10 +145,40 @@ class Config
|
||||||
$db_info_without_ftp = clone $db_info;
|
$db_info_without_ftp = clone $db_info;
|
||||||
unset($db_info_without_ftp->ftp_info);
|
unset($db_info_without_ftp->ftp_info);
|
||||||
$warning = '// DO NOT EDIT THIS FILE. CHANGES WILL NOT BE APPLIED.' . "\n" . '// TO CHANGE RHYMIX SYSTEM CONFIGURATION, EDIT config.php INSTEAD.';
|
$warning = '// DO NOT EDIT THIS FILE. CHANGES WILL NOT BE APPLIED.' . "\n" . '// TO CHANGE RHYMIX SYSTEM CONFIGURATION, EDIT config.php INSTEAD.';
|
||||||
$buff = '<?php' . "\n\n" . $warning . "\n\n" . '$db_info = ' . var_export_clean($db_info_without_ftp) . ';' . "\n";
|
$buff = '<?php' . "\n\n" . $warning . "\n\n" . '$db_info = ' . self::serialize($db_info_without_ftp) . ';' . "\n";
|
||||||
Storage::write(\RX_BASEDIR . self::$old_db_config_filename, $buff);
|
Storage::write(\RX_BASEDIR . self::$old_db_config_filename, $buff);
|
||||||
$buff = '<?php' . "\n\n" . $warning . "\n\n" . '$ftp_info = ' . var_export_clean($ftp_info) . ';' . "\n";
|
$buff = '<?php' . "\n\n" . $warning . "\n\n" . '$ftp_info = ' . self::serialize($ftp_info) . ';' . "\n";
|
||||||
Storage::write(\RX_BASEDIR . self::$old_ftp_config_filename, $buff);
|
Storage::write(\RX_BASEDIR . self::$old_ftp_config_filename, $buff);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize a value for insertion into a PHP-based configuration file.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function serialize($value)
|
||||||
|
{
|
||||||
|
if (is_object($value))
|
||||||
|
{
|
||||||
|
return '(object)' . self::serialize((array)$value);
|
||||||
|
}
|
||||||
|
elseif (is_array($value))
|
||||||
|
{
|
||||||
|
$value = var_export($value, true);
|
||||||
|
$value = preg_replace('/array \(\n/', "array(\n", $value);
|
||||||
|
$value = preg_replace('/=>\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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ class Debug
|
||||||
if (config('debug.write_error_log') === 'all' && self::isEnabledForCurrentUser())
|
if (config('debug.write_error_log') === 'all' && self::isEnabledForCurrentUser())
|
||||||
{
|
{
|
||||||
$log_entry = str_replace("\0", '', sprintf('Rhymix Debug: %s in %s on line %d',
|
$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);
|
error_log($log_entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,18 +82,18 @@ class LangParser
|
||||||
{
|
{
|
||||||
foreach ($subvalue as $subsubkey => $subsubvalue)
|
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
|
else
|
||||||
{
|
{
|
||||||
$buff .= '$lang->' . $key . "['$subkey']" . ' = ' . var_export_clean($subvalue) . ";\n";
|
$buff .= '$lang->' . $key . "['$subkey']" . ' = ' . var_export($subvalue, true) . ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$buff .= '$lang->' . $key . ' = ' . var_export_clean($value) . ";\n";
|
$buff .= '$lang->' . $key . ' = ' . var_export($value, true) . ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Storage::write($output_filename, $buff);
|
Storage::write($output_filename, $buff);
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ class Storage
|
||||||
{
|
{
|
||||||
$comment = "/* $comment */\n";
|
$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) . ');');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -409,22 +409,6 @@ function url2path($url)
|
||||||
return Rhymix\Framework\URL::toServerPath($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.
|
* 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 '#'.
|
* This function can handle both 6-digit and 3-digit notations, optionally prefixed with '#'.
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ Debug Entries
|
||||||
{
|
{
|
||||||
if (is_scalar($entry->message))
|
if (is_scalar($entry->message))
|
||||||
{
|
{
|
||||||
$entry->message = var_export_clean($entry->message);
|
$entry->message = var_export($entry->message, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,9 @@ class ConfigTest extends \Codeception\TestCase\Test
|
||||||
Rhymix\Framework\Config::set('foo.bar', $rand = mt_rand());
|
Rhymix\Framework\Config::set('foo.bar', $rand = mt_rand());
|
||||||
$this->assertEquals(array('bar' => $rand), Rhymix\Framework\Config::get('foo'));
|
$this->assertEquals(array('bar' => $rand), Rhymix\Framework\Config::get('foo'));
|
||||||
$this->assertEquals($rand, Rhymix\Framework\Config::get('foo.bar'));
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,21 +103,6 @@ class FunctionsTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals('Rhymix ^~', base64_decode_urlsafe('Umh5bWl4IF5-'));
|
$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()
|
public function testHex2Rgb2Hex()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(128, 128, 128), hex2rgb('808080'));
|
$this->assertEquals(array(128, 128, 128), hex2rgb('808080'));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue