diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php index 8c561c63..defc50c6 100644 --- a/phpdotnet/phd/Config.php +++ b/phpdotnet/phd/Config.php @@ -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 @@ public function init(array $configOptions): void { throw new \Exception("Invalid option supplied: $option"); } + if (\in_array($option, self::NON_SERIALIZABLE_PROPERTIES, true)) { + continue; + } + $this->$option = $value; } @@ -83,12 +96,18 @@ public function init(array $configOptions): void { } /** - * Returns all configuration options and their values + * Returns all serializable configuration options and their values * * @return array */ - 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; } /** diff --git a/render.php b/render.php index dbd451fa..be2d0c06 100644 --- a/render.php +++ b/render.php @@ -74,7 +74,7 @@ if ($config->saveConfig) { $outputHandler->v("Writing the config file", VERBOSE_MESSAGES); - file_put_contents("phd.config.php", "getAllFiltered(), 1) . ";"); + file_put_contents("phd.config.php", "getAllSerializableProperties(), 1) . ";"); } if ($config->quit) { diff --git a/tests/GH-225.phpt b/tests/GH-225.phpt new file mode 100644 index 00000000..bf418192 --- /dev/null +++ b/tests/GH-225.phpt @@ -0,0 +1,31 @@ +--TEST-- +GH-225 - SaveConfig tries to overwrite readonly property +--ARGS-- +--docbook tests/data/bug-GH-225.xml --quit +--FILE-- + 'Should not be imported', +);"); + +require_once __DIR__ . "/../render.php"; +?> +--CLEAN-- + +--EXPECTF-- +%s[%d:%d:%d - Heads up ]%s Loaded config from existing file diff --git a/tests/data/bug-GH-225.xml b/tests/data/bug-GH-225.xml new file mode 100644 index 00000000..b62ca013 --- /dev/null +++ b/tests/data/bug-GH-225.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file