File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,15 @@ class Config
5757 public string $ phpwebSourcesFilename = '' ;
5858 public string $ phpwebHistoryFilename = '' ;
5959
60+ private const NON_SERIALIZABLE_PROPERTIES = [
61+ "copyright " ,
62+ "indexCache " ,
63+ "phpErrorOutput " ,
64+ "userErrorOutput " ,
65+ "phdInfoOutput " ,
66+ "phdWarningOutput " ,
67+ ];
68+
6069 public function __construct () {
6170 $ this ->copyright = 'Copyright(c) 2007- ' . \date ('Y ' ) . ' The PHP Documentation Group ' ;
6271
@@ -76,19 +85,29 @@ public function init(array $configOptions): void {
7685 throw new \Exception ("Invalid option supplied: $ option " );
7786 }
7887
88+ if (\in_array ($ option , self ::NON_SERIALIZABLE_PROPERTIES , true )) {
89+ continue ;
90+ }
91+
7992 $ this ->$ option = $ value ;
8093 }
8194
8295 \error_reporting ($ GLOBALS ['olderrrep ' ] | $ this ->verbose );
8396 }
8497
8598 /**
86- * Returns all configuration options and their values
99+ * Returns all serializable configuration options and their values
87100 *
88101 * @return array<string, mixed>
89102 */
90- public function getAllFiltered (): array {
91- return \get_object_vars ($ this );
103+ public function getAllSerializableProperties (): array {
104+ $ object_vars = \get_object_vars ($ this );
105+
106+ foreach (self ::NON_SERIALIZABLE_PROPERTIES as $ property ) {
107+ unset($ object_vars [$ property ]);
108+ }
109+
110+ return $ object_vars ;
92111 }
93112
94113 /**
Original file line number Diff line number Diff line change 7474
7575if ($ config ->saveConfig ) {
7676 $ outputHandler ->v ("Writing the config file " , VERBOSE_MESSAGES );
77- file_put_contents ("phd.config.php " , "<?php \nreturn " . var_export ($ config ->getAllFiltered (), 1 ) . "; " );
77+ file_put_contents ("phd.config.php " , "<?php \nreturn " . var_export ($ config ->getAllSerializableProperties (), 1 ) . "; " );
7878}
7979
8080if ($ config ->quit ) {
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-225 - SaveConfig tries to overwrite readonly property
3+ --ARGS--
4+ --docbook tests/data/bug-GH-225.xml --quit
5+ --FILE--
6+ <?php
7+ namespace phpdotnet \phd ;
8+
9+ if (!\file_exists (__DIR__ . "/../output/ " )) {
10+ \mkdir (__DIR__ . "/../output/ " , 0777 , true );
11+ }
12+
13+ if (\file_exists (__DIR__ . "/../phd.config.php " )) {
14+ \unlink (__DIR__ . "/../phd.config.php " );
15+ }
16+
17+ \file_put_contents (__DIR__ . "/../phd.config.php " ,
18+ "<?php
19+ return array (
20+ 'copyright' => 'Should not be imported',
21+ ); " );
22+
23+ require_once __DIR__ . "/../render.php " ;
24+ ?>
25+ --CLEAN--
26+ <?php
27+ \unlink (__DIR__ . "/../phd.config.php " );
28+ \rmdir (__DIR__ . "/../output/ " );
29+ ?>
30+ --EXPECTF--
31+ %s[%d:%d:%d - Heads up ]%s Loaded config from existing file
Original file line number Diff line number Diff line change 1+ <test >
2+ </test >
You can’t perform that action at this time.
0 commit comments