4848use const CONFIG_FILE ;
4949use const E_USER_ERROR ;
5050
51- final class Common
51+ final class Application
5252{
5353 private static ServerRequest |null $ request = null ;
5454
55+ public static function init (): self
56+ {
57+ /** @var Application $application */
58+ $ application = Core::getContainerBuilder ()->get (self ::class);
59+
60+ return $ application ;
61+ }
62+
5563 /**
5664 * Misc stuff and REQUIRED by ALL the scripts.
5765 * MUST be included by every script
@@ -80,33 +88,28 @@ final class Common
8088 * - db connection
8189 * - authentication work
8290 */
83- public static function run (bool $ isSetupPage = false ): void
91+ public function run (bool $ isSetupPage = false ): void
8492 {
85- $ GLOBALS ['lang ' ] ??= null ;
86- $ GLOBALS ['theme ' ] ??= null ;
87- $ GLOBALS ['urlParams ' ] ??= null ;
88- $ GLOBALS ['token_mismatch ' ] ??= null ;
93+ $ container = Core::getContainerBuilder ();
8994
9095 $ request = self ::getRequest ();
9196 $ route = $ request ->getRoute ();
9297
9398 $ isMinimumCommon = $ isSetupPage || $ route === '/import-status ' || $ route === '/url ' || $ route === '/messages ' ;
9499
95- $ container = Core::getContainerBuilder ();
96-
97100 /** @var ErrorHandler $errorHandler */
98101 $ errorHandler = $ container ->get ('error_handler ' );
99102 $ GLOBALS ['errorHandler ' ] = $ errorHandler ;
100103
101104 try {
102- self :: checkRequiredPhpExtensions ();
105+ $ this -> checkRequiredPhpExtensions ();
103106 } catch (MissingExtensionException $ exception ) {
104- echo self :: getGenericError ($ exception ->getMessage ());
107+ echo $ this -> getGenericError ($ exception ->getMessage ());
105108
106109 return ;
107110 }
108111
109- self :: configurePhpSettings ();
112+ $ this -> configurePhpSettings ();
110113
111114 /** @var Config $config */
112115 $ config = $ container ->get ('config ' );
@@ -115,19 +118,19 @@ public static function run(bool $isSetupPage = false): void
115118 try {
116119 $ config ->loadAndCheck (CONFIG_FILE );
117120 } catch (ConfigException $ exception ) {
118- echo self :: getGenericError ($ exception ->getMessage ());
121+ echo $ this -> getGenericError ($ exception ->getMessage ());
119122
120123 return ;
121124 }
122125
123- $ request = self :: updateUriScheme ($ config , $ request );
126+ $ request = $ this -> updateUriScheme ($ config , $ request );
124127
125128 if ($ route !== '/messages ' ) {
126129 try {
127130 // Include session handling after the globals, to prevent overwriting.
128131 Session::setUp ($ config , $ errorHandler );
129132 } catch (SessionHandlerException $ exception ) {
130- echo self :: getGenericError ($ exception ->getMessage ());
133+ echo $ this -> getGenericError ($ exception ->getMessage ());
131134
132135 return ;
133136 }
@@ -147,10 +150,10 @@ public static function run(bool $isSetupPage = false): void
147150 $ GLOBALS ['urlParams ' ] = [];
148151 $ container ->setParameter ('url_params ' , $ GLOBALS ['urlParams ' ]);
149152
150- self :: setGotoAndBackGlobals ($ container , $ config );
151- self :: checkTokenRequestParam ();
152- self :: setDatabaseAndTableFromRequest ($ container , $ request );
153- self :: setSQLQueryGlobalFromRequest ($ container , $ request );
153+ $ this -> setGotoAndBackGlobals ($ container , $ config );
154+ $ this -> checkTokenRequestParam ();
155+ $ this -> setDatabaseAndTableFromRequest ($ container , $ request );
156+ $ this -> setSQLQueryGlobalFromRequest ($ container , $ request );
154157
155158 //$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
156159 //$_REQUEST['server']; // checked later in this file
@@ -172,21 +175,21 @@ public static function run(bool $isSetupPage = false): void
172175 $ config ->checkPermissions ();
173176 $ config ->checkErrors ();
174177 } catch (ConfigException $ exception ) {
175- echo self :: getGenericError ($ exception ->getMessage ());
178+ echo $ this -> getGenericError ($ exception ->getMessage ());
176179
177180 return ;
178181 }
179182
180183 try {
181- self :: checkServerConfiguration ();
182- self :: checkRequest ();
184+ $ this -> checkServerConfiguration ();
185+ $ this -> checkRequest ();
183186 } catch (RuntimeException $ exception ) {
184- echo self :: getGenericError ($ exception ->getMessage ());
187+ echo $ this -> getGenericError ($ exception ->getMessage ());
185188
186189 return ;
187190 }
188191
189- self :: setCurrentServerGlobal ($ container , $ config , $ request ->getParam ('server ' ));
192+ $ this -> setCurrentServerGlobal ($ container , $ config , $ request ->getParam ('server ' ));
190193
191194 $ GLOBALS ['cfg ' ] = $ config ->settings ;
192195 $ settings = $ config ->getSettings ();
@@ -206,7 +209,7 @@ public static function run(bool $isSetupPage = false): void
206209 }
207210
208211 if ($ isSetupPage ) {
209- self :: setupPageBootstrap ($ config );
212+ $ this -> setupPageBootstrap ($ config );
210213 Routing::callSetupController ($ request );
211214
212215 return ;
@@ -237,7 +240,7 @@ public static function run(bool $isSetupPage = false): void
237240 try {
238241 $ authPlugin = $ authPluginFactory ->create ();
239242 } catch (AuthenticationPluginException $ exception ) {
240- echo self :: getGenericError ($ exception ->getMessage ());
243+ echo $ this -> getGenericError ($ exception ->getMessage ());
241244
242245 return ;
243246 }
@@ -253,15 +256,15 @@ public static function run(bool $isSetupPage = false): void
253256 // phpcs:enable
254257 }
255258
256- self :: connectToDatabaseServer ($ GLOBALS ['dbi ' ], $ authPlugin , $ currentServer );
259+ $ this -> connectToDatabaseServer ($ GLOBALS ['dbi ' ], $ authPlugin , $ currentServer );
257260 $ authPlugin ->rememberCredentials ();
258261 $ authPlugin ->checkTwoFactor ();
259262
260263 /* Log success */
261264 Logging::logUser ($ config , $ currentServer ->user );
262265
263266 if ($ GLOBALS ['dbi ' ]->getVersion () < $ settings ->mysqlMinVersion ['internal ' ]) {
264- echo self :: getGenericError (sprintf (
267+ echo $ this -> getGenericError (sprintf (
265268 __ ('You should upgrade to %s %s or later. ' ),
266269 'MySQL ' ,
267270 $ settings ->mysqlMinVersion ['human ' ],
@@ -322,7 +325,7 @@ public static function run(bool $isSetupPage = false): void
322325 /**
323326 * Checks that required PHP extensions are there.
324327 */
325- private static function checkRequiredPhpExtensions (): void
328+ private function checkRequiredPhpExtensions (): void
326329 {
327330 /**
328331 * Warning about mbstring.
@@ -374,7 +377,7 @@ private static function checkRequiredPhpExtensions(): void
374377 /**
375378 * Applies changes to PHP configuration.
376379 */
377- private static function configurePhpSettings (): void
380+ private function configurePhpSettings (): void
378381 {
379382 /**
380383 * Set utf-8 encoding for PHP
@@ -397,7 +400,7 @@ private static function configurePhpSettings(): void
397400 date_default_timezone_set (@date_default_timezone_get ());
398401 }
399402
400- private static function setGotoAndBackGlobals (ContainerInterface $ container , Config $ config ): void
403+ private function setGotoAndBackGlobals (ContainerInterface $ container , Config $ config ): void
401404 {
402405 $ GLOBALS ['back ' ] ??= null ;
403406 $ GLOBALS ['urlParams ' ] ??= null ;
@@ -442,7 +445,7 @@ private static function setGotoAndBackGlobals(ContainerInterface $container, Con
442445 * GET Requests would never have token and therefore checking
443446 * mis-match does not make sense.
444447 */
445- public static function checkTokenRequestParam (): void
448+ public function checkTokenRequestParam (): void
446449 {
447450 $ GLOBALS ['token_mismatch ' ] = true ;
448451 $ GLOBALS ['token_provided ' ] = false ;
@@ -478,7 +481,7 @@ public static function checkTokenRequestParam(): void
478481 Sanitize::removeRequestVars ($ allowList );
479482 }
480483
481- private static function setDatabaseAndTableFromRequest (ContainerInterface $ container , ServerRequest $ request ): void
484+ private function setDatabaseAndTableFromRequest (ContainerInterface $ container , ServerRequest $ request ): void
482485 {
483486 $ GLOBALS ['urlParams ' ] ??= null ;
484487
@@ -500,7 +503,7 @@ private static function setDatabaseAndTableFromRequest(ContainerInterface $conta
500503 /**
501504 * Check whether PHP configuration matches our needs.
502505 */
503- private static function checkServerConfiguration (): void
506+ private function checkServerConfiguration (): void
504507 {
505508 /**
506509 * As we try to handle charsets by ourself, mbstring overloads just
@@ -533,7 +536,7 @@ private static function checkServerConfiguration(): void
533536 /**
534537 * Checks request and fails with fatal error if something problematic is found
535538 */
536- private static function checkRequest (): void
539+ private function checkRequest (): void
537540 {
538541 if (isset ($ _REQUEST ['GLOBALS ' ]) || isset ($ _FILES ['GLOBALS ' ])) {
539542 throw new RuntimeException (__ ('GLOBALS overwrite attempt ' ));
@@ -549,7 +552,7 @@ private static function checkRequest(): void
549552 throw new RuntimeException (__ ('possible exploit ' ));
550553 }
551554
552- private static function connectToDatabaseServer (
555+ private function connectToDatabaseServer (
553556 DatabaseInterface $ dbi ,
554557 AuthenticationPlugin $ auth ,
555558 Server $ currentServer ,
@@ -589,13 +592,13 @@ public static function getRequest(): ServerRequest
589592 return self ::$ request ;
590593 }
591594
592- private static function setupPageBootstrap (Config $ config ): void
595+ private function setupPageBootstrap (Config $ config ): void
593596 {
594597 // use default error handler
595598 restore_error_handler ();
596599
597600 // Save current language in a cookie, since it was not set in Common::run().
598- $ config ->setCookie ('pma_lang ' , ( string ) $ GLOBALS ['lang ' ]);
601+ $ config ->setCookie ('pma_lang ' , $ GLOBALS ['lang ' ]);
599602 $ config ->set ('is_setup ' , true );
600603
601604 $ GLOBALS ['ConfigFile ' ] = new ConfigFile ();
@@ -619,7 +622,7 @@ private static function setupPageBootstrap(Config $config): void
619622 ob_start ();
620623 }
621624
622- private static function setSQLQueryGlobalFromRequest (ContainerInterface $ container , ServerRequest $ request ): void
625+ private function setSQLQueryGlobalFromRequest (ContainerInterface $ container , ServerRequest $ request ): void
623626 {
624627 $ sqlQuery = '' ;
625628 if ($ request ->isPost ()) {
@@ -634,7 +637,7 @@ private static function setSQLQueryGlobalFromRequest(ContainerInterface $contain
634637 $ container ->setParameter ('sql_query ' , $ sqlQuery );
635638 }
636639
637- private static function setCurrentServerGlobal (
640+ private function setCurrentServerGlobal (
638641 ContainerInterface $ container ,
639642 Config $ config ,
640643 mixed $ serverParamFromRequest ,
@@ -646,7 +649,7 @@ private static function setCurrentServerGlobal(
646649 $ container ->setParameter ('url_params ' , $ GLOBALS ['urlParams ' ]);
647650 }
648651
649- private static function getGenericError (string $ message ): string
652+ private function getGenericError (string $ message ): string
650653 {
651654 return (new Template ())->render ('error/generic ' , [
652655 'lang ' => $ GLOBALS ['lang ' ] ?? 'en ' ,
@@ -655,7 +658,7 @@ private static function getGenericError(string $message): string
655658 ]);
656659 }
657660
658- private static function updateUriScheme (Config $ config , ServerRequest $ request ): ServerRequest
661+ private function updateUriScheme (Config $ config , ServerRequest $ request ): ServerRequest
659662 {
660663 $ uriScheme = $ config ->isHttps () ? 'https ' : 'http ' ;
661664 $ uri = $ request ->getUri ();
0 commit comments