Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions phpdotnet/phd/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -76,19 +85,29 @@ 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;
}

\error_reporting($GLOBALS['olderrrep'] | $this->verbose);
}

/**
* 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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion render.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions tests/GH-225.phpt
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/data/bug-GH-225.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<test>
</test>