Add option to skip serialization when saving PHP data to file

This commit is contained in:
Kijin Sung 2021-06-20 22:01:37 +09:00
parent c7f84a4dfe
commit f416b7c8a4

View file

@ -356,15 +356,24 @@ class Storage
* @param string $filename * @param string $filename
* @param mixed $data * @param mixed $data
* @param string $comment (optional) * @param string $comment (optional)
* @param bool $serialize (optional)
* @return string|false * @return string|false
*/ */
public static function writePHPData($filename, $data, $comment = null) public static function writePHPData($filename, $data, $comment = null, $serialize = true)
{ {
if ($comment !== null) if ($comment !== null)
{ {
$comment = "/* $comment */\n"; $comment = "/* $comment */\n";
} }
return self::write($filename, '<' . '?php ' . $comment . 'return unserialize(' . var_export(serialize($data), true) . ');'); if ($serialize)
{
$content = '<' . '?php ' . $comment . 'return unserialize(' . var_export(serialize($data), true) . ');';
}
else
{
$content = '<' . '?php ' . $comment . 'return ' . var_export($data, true) . ';';
}
return self::write($filename, $content);
} }
/** /**