66
77use Fig \Http \Message \StatusCodeInterface ;
88use Laminas \HttpHandlerRunner \Emitter \SapiEmitter ;
9+ use Laminas \HttpHandlerRunner \RequestHandlerRunner ;
910use PhpMyAdmin \Config \ConfigFile ;
1011use PhpMyAdmin \Config \Settings \Server ;
1112use PhpMyAdmin \ConfigStorage \Relation ;
1213use PhpMyAdmin \Dbal \Connection ;
1314use PhpMyAdmin \Exceptions \AuthenticationPluginException ;
1415use PhpMyAdmin \Exceptions \ConfigException ;
15- use PhpMyAdmin \Exceptions \MissingExtensionException ;
1616use PhpMyAdmin \Exceptions \SessionHandlerException ;
1717use PhpMyAdmin \Http \Factory \ResponseFactory ;
1818use PhpMyAdmin \Http \Factory \ServerRequestFactory ;
19+ use PhpMyAdmin \Http \Handler \ApplicationHandler ;
20+ use PhpMyAdmin \Http \Handler \QueueRequestHandler ;
1921use PhpMyAdmin \Http \Response ;
2022use PhpMyAdmin \Http \ServerRequest ;
2123use PhpMyAdmin \Identifiers \DatabaseName ;
2224use PhpMyAdmin \Identifiers \TableName ;
25+ use PhpMyAdmin \Middleware \ErrorHandling ;
26+ use PhpMyAdmin \Middleware \OutputBuffering ;
27+ use PhpMyAdmin \Middleware \PhpExtensionsChecking ;
2328use PhpMyAdmin \Plugins \AuthenticationPlugin ;
2429use PhpMyAdmin \Plugins \AuthenticationPluginFactory ;
2530use PhpMyAdmin \Routing \Routing ;
2631use PhpMyAdmin \SqlParser \Lexer ;
2732use PhpMyAdmin \Theme \ThemeManager ;
2833use PhpMyAdmin \Tracking \Tracker ;
34+ use Psr \Http \Message \ResponseInterface ;
35+ use Psr \Http \Message \ServerRequestInterface ;
2936use RuntimeException ;
3037use Symfony \Component \DependencyInjection \ContainerInterface ;
38+ use Throwable ;
3139
3240use function __ ;
3341use function count ;
5159use const CONFIG_FILE ;
5260use const E_USER_ERROR ;
5361
54- final class Application
62+ class Application
5563{
5664 private static ServerRequest |null $ request = null ;
5765
@@ -73,32 +81,33 @@ public static function init(): self
7381
7482 public function run (bool $ isSetupPage = false ): void
7583 {
76- $ request = self ::getRequest ()->withAttribute ('isSetupPage ' , $ isSetupPage );
77- $ response = $ this ->handle ($ request );
78- if ($ response === null ) {
79- return ;
80- }
81-
82- $ emitter = new SapiEmitter ();
83- $ emitter ->emit ($ response );
84+ $ requestHandler = new QueueRequestHandler (new ApplicationHandler ($ this ));
85+ $ requestHandler ->add (new ErrorHandling ($ this ->errorHandler ));
86+ $ requestHandler ->add (new OutputBuffering ());
87+ $ requestHandler ->add (new PhpExtensionsChecking ($ this , $ this ->template , $ this ->responseFactory ));
88+
89+ $ runner = new RequestHandlerRunner (
90+ $ requestHandler ,
91+ new SapiEmitter (),
92+ static fn (): ServerRequestInterface => self ::getRequest ()->withAttribute ('isSetupPage ' , $ isSetupPage ),
93+ function (Throwable $ throwable ): ResponseInterface {
94+ $ response = $ this ->responseFactory ->createResponse (StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR );
95+ $ response ->getBody ()->write (sprintf ('An error occurred: %s ' , $ throwable ->getMessage ()));
96+
97+ return $ response ;
98+ },
99+ );
100+
101+ $ runner ->run ();
84102 }
85103
86- private function handle (ServerRequest $ request ): Response |null
104+ public function handle (ServerRequest $ request ): Response |null
87105 {
88106 $ isSetupPage = (bool ) $ request ->getAttribute ('isSetupPage ' );
89107
90108 $ GLOBALS ['errorHandler ' ] = $ this ->errorHandler ;
91109 $ GLOBALS ['config ' ] = $ this ->config ;
92110
93- try {
94- $ this ->checkRequiredPhpExtensions ();
95- } catch (MissingExtensionException $ exception ) {
96- // Disables template caching because the cache directory is not known yet.
97- $ this ->template ->disableCache ();
98-
99- return $ this ->getGenericErrorResponse ($ exception ->getMessage ());
100- }
101-
102111 $ resultOfServerConfigurationCheck = $ this ->checkServerConfiguration ();
103112 if ($ resultOfServerConfigurationCheck !== null ) {
104113 return $ this ->getGenericErrorResponse ($ resultOfServerConfigurationCheck );
@@ -316,7 +325,7 @@ private function handle(ServerRequest $request): Response|null
316325 /**
317326 * Checks that required PHP extensions are there.
318327 */
319- private function checkRequiredPhpExtensions (): void
328+ public function checkRequiredPhpExtensions (): void
320329 {
321330 /**
322331 * Warning about mbstring.
0 commit comments