88use PhpMyAdmin \ConfigStorage \Relation ;
99use PhpMyAdmin \Dbal \DatabaseName ;
1010use PhpMyAdmin \Dbal \TableName ;
11+ use PhpMyAdmin \Exceptions \ConfigException ;
1112use PhpMyAdmin \Exceptions \MissingExtensionException ;
1213use PhpMyAdmin \Http \Factory \ServerRequestFactory ;
1314use PhpMyAdmin \Http \ServerRequest ;
@@ -106,11 +107,7 @@ public static function run(bool $isSetupPage = false): void
106107 try {
107108 self ::checkRequiredPhpExtensions ();
108109 } catch (MissingExtensionException $ exception ) {
109- echo (new Template ())->render ('error/generic ' , [
110- 'lang ' => $ GLOBALS ['lang ' ] ?? 'en ' ,
111- 'dir ' => $ GLOBALS ['text_dir ' ] ?? 'ltr ' ,
112- 'error_message ' => $ exception ->getMessage (),
113- ]);
110+ echo self ::getGenericError ($ exception ->getMessage ());
114111
115112 return ;
116113 }
@@ -127,9 +124,16 @@ public static function run(bool $isSetupPage = false): void
127124
128125 /** @var Config $config */
129126 $ config = $ GLOBALS ['containerBuilder ' ]->get ('config ' );
130- $ config ->loadAndCheck (CONFIG_FILE );
131127 $ GLOBALS ['config ' ] = $ config ;
132128
129+ try {
130+ $ config ->loadAndCheck (CONFIG_FILE );
131+ } catch (ConfigException $ exception ) {
132+ echo self ::getGenericError ($ exception ->getMessage ());
133+
134+ return ;
135+ }
136+
133137 if ($ route !== '/messages ' ) {
134138 // Include session handling after the globals, to prevent overwriting.
135139 Session::setUp ($ config , $ errorHandler );
@@ -166,22 +170,24 @@ public static function run(bool $isSetupPage = false): void
166170 $ language = LanguageManager::getInstance ()->selectLanguage ();
167171 $ language ->activate ();
168172
169- /**
170- * check for errors occurred while loading configuration
171- * this check is done here after loading language files to present errors in locale
172- */
173- $ config ->checkPermissions ();
174- $ config ->checkErrors ();
173+ try {
174+ /**
175+ * check for errors occurred while loading configuration
176+ * this check is done here after loading language files to present errors in locale
177+ */
178+ $ config ->checkPermissions ();
179+ $ config ->checkErrors ();
180+ } catch (ConfigException $ exception ) {
181+ echo self ::getGenericError ($ exception ->getMessage ());
182+
183+ return ;
184+ }
175185
176186 try {
177187 self ::checkServerConfiguration ();
178188 self ::checkRequest ();
179189 } catch (RuntimeException $ exception ) {
180- echo (new Template ())->render ('error/generic ' , [
181- 'lang ' => $ GLOBALS ['lang ' ] ?? 'en ' ,
182- 'dir ' => $ GLOBALS ['text_dir ' ] ?? 'ltr ' ,
183- 'error_message ' => $ exception ->getMessage (),
184- ]);
190+ echo self ::getGenericError ($ exception ->getMessage ());
185191
186192 return ;
187193 }
@@ -252,15 +258,11 @@ public static function run(bool $isSetupPage = false): void
252258 Logging::logUser ($ GLOBALS ['cfg ' ]['Server ' ]['user ' ]);
253259
254260 if ($ GLOBALS ['dbi ' ]->getVersion () < $ GLOBALS ['cfg ' ]['MysqlMinVersion ' ]['internal ' ]) {
255- echo (new Template ())->render ('error/generic ' , [
256- 'lang ' => $ GLOBALS ['lang ' ] ?? 'en ' ,
257- 'dir ' => $ GLOBALS ['text_dir ' ] ?? 'ltr ' ,
258- 'error_message ' => sprintf (
259- __ ('You should upgrade to %s %s or later. ' ),
260- 'MySQL ' ,
261- (string ) $ GLOBALS ['cfg ' ]['MysqlMinVersion ' ]['human ' ]
262- ),
263- ]);
261+ echo self ::getGenericError (sprintf (
262+ __ ('You should upgrade to %s %s or later. ' ),
263+ 'MySQL ' ,
264+ (string ) $ GLOBALS ['cfg ' ]['MysqlMinVersion ' ]['human ' ]
265+ ));
264266
265267 return ;
266268 }
@@ -689,4 +691,13 @@ private static function setCurrentServerGlobal(Config $config): void
689691 $ GLOBALS ['containerBuilder ' ]->setParameter ('server ' , $ server );
690692 $ GLOBALS ['containerBuilder ' ]->setParameter ('url_params ' , $ GLOBALS ['urlParams ' ]);
691693 }
694+
695+ private static function getGenericError (string $ message ): string
696+ {
697+ return (new Template ())->render ('error/generic ' , [
698+ 'lang ' => $ GLOBALS ['lang ' ] ?? 'en ' ,
699+ 'dir ' => $ GLOBALS ['text_dir ' ] ?? 'ltr ' ,
700+ 'error_message ' => $ message ,
701+ ]);
702+ }
692703}
0 commit comments