[DOC-CVS] [phd] master: Fix GH-225 (#226)
[email protected] (haszi via GitHub)
| Newsgroups | php.doc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: haszi (haszi)
Committer: GitHub (web-flow)
Pusher: haszi
Date: 2026-02-05T22:25:12+01:00
Commit: https://github.com/php/phd/commit/e012bdf3c10f79bad14210e93189485b4d012f38
Raw diff: https://github.com/php/phd/commit/e012bdf3c10f79bad14210e93189485b4d012f38.diff
Fix GH-225 (#226)
* Closes GH-225 - cannot reload saved configuration
* Add test
* Prevent serializing and deserializing non-serializable properties
Changed paths:
A tests/GH-225.phpt
A tests/data/bug-GH-225.xml
M phpdotnet/phd/Config.php
M render.php
Diff:
diff --git a/phpdotnet/phd/Config.php b/phpdotnet/phd/Config.php
index e23a8376..642c8aef 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<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;
}
/**
diff --git a/render.php b/render.php
index c9600edc..94c9e096 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", "<?php\nreturn " . var_export($config->getAllFiltered(), 1) . ";");
+ file_put_contents("phd.config.php", "<?php\nreturn " . var_export($config->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--
+<?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
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 @@
+<test>
+</test>
\ No newline at end of file