mirror of
https://github.com/php/phd.git
synced 2026-03-23 22:52:05 +01:00
Fix GH-225 (#226)
* Closes GH-225 - cannot reload saved configuration * Add test * Prevent serializing and deserializing non-serializable properties
This commit is contained in:
@@ -57,6 +57,15 @@ class Config
|
||||
public string $phpwebSourcesFilename = '';
|
||||
public string $phpwebHistoryFilename = '';
|
||||
|
||||
private const NON_SERIALIZABLE_PROPERTIES = [
|
||||
"copyright",
|
||||
"indexCache",
|
||||
"phpErrorOutput",
|
||||
"userErrorOutput",
|
||||
"phdInfoOutput",
|
||||
"phdWarningOutput",
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
$this->copyright = 'Copyright(c) 2007-' . \date('Y') . ' The PHP Documentation Group';
|
||||
|
||||
@@ -76,6 +85,10 @@ class Config
|
||||
throw new \Exception("Invalid option supplied: $option");
|
||||
}
|
||||
|
||||
if (\in_array($option, self::NON_SERIALIZABLE_PROPERTIES, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->$option = $value;
|
||||
}
|
||||
|
||||
@@ -83,12 +96,18 @@ class Config
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all configuration options and their values
|
||||
* Returns all serializable configuration options and their values
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getAllFiltered(): array {
|
||||
return \get_object_vars($this);
|
||||
public function getAllSerializableProperties(): array {
|
||||
$object_vars = \get_object_vars($this);
|
||||
|
||||
foreach (self::NON_SERIALIZABLE_PROPERTIES as $property) {
|
||||
unset($object_vars[$property]);
|
||||
}
|
||||
|
||||
return $object_vars;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,7 +74,7 @@ if (!$conf) {
|
||||
|
||||
if ($config->saveConfig) {
|
||||
$outputHandler->v("Writing the config file", VERBOSE_MESSAGES);
|
||||
file_put_contents("phd.config.php", "<?php\nreturn " . var_export($config->getAllFiltered(), 1) . ";");
|
||||
file_put_contents("phd.config.php", "<?php\nreturn " . var_export($config->getAllSerializableProperties(), 1) . ";");
|
||||
}
|
||||
|
||||
if ($config->quit) {
|
||||
|
||||
31
tests/GH-225.phpt
Normal file
31
tests/GH-225.phpt
Normal file
@@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
GH-225 - SaveConfig tries to overwrite readonly property
|
||||
--ARGS--
|
||||
--docbook tests/data/bug-GH-225.xml --quit
|
||||
--FILE--
|
||||
<?php
|
||||
namespace phpdotnet\phd;
|
||||
|
||||
if (!\file_exists(__DIR__ . "/../output/")) {
|
||||
\mkdir(__DIR__ . "/../output/", 0777, true);
|
||||
}
|
||||
|
||||
if (\file_exists(__DIR__ . "/../phd.config.php")) {
|
||||
\unlink(__DIR__ . "/../phd.config.php");
|
||||
}
|
||||
|
||||
\file_put_contents(__DIR__ . "/../phd.config.php",
|
||||
"<?php
|
||||
return array (
|
||||
'copyright' => 'Should not be imported',
|
||||
);");
|
||||
|
||||
require_once __DIR__ . "/../render.php";
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
\unlink(__DIR__ . "/../phd.config.php");
|
||||
\rmdir(__DIR__ . "/../output/");
|
||||
?>
|
||||
--EXPECTF--
|
||||
%s[%d:%d:%d - Heads up ]%s Loaded config from existing file
|
||||
2
tests/data/bug-GH-225.xml
Normal file
2
tests/data/bug-GH-225.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<test>
|
||||
</test>
|
||||
Reference in New Issue
Block a user