Move system environment check into a middleware
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 31 May 2022 13:48:24 +0000 (15:48 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 31 May 2022 13:48:24 +0000 (15:48 +0200)
wcfsetup/install/files/lib/http/middleware/CheckSystemEnvironment.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

diff --git a/wcfsetup/install/files/lib/http/middleware/CheckSystemEnvironment.class.php b/wcfsetup/install/files/lib/http/middleware/CheckSystemEnvironment.class.php
new file mode 100644 (file)
index 0000000..a88ff17
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+namespace wcf\http\middleware;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use wcf\system\exception\NamedUserException;
+use wcf\system\request\RequestHandler;
+use wcf\system\WCF;
+
+/**
+ * Checks whether the system environment is unacceptable and prevents processing in that case.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2022 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Http\Middleware
+ * @since   5.6
+ */
+final class CheckSystemEnvironment implements MiddlewareInterface
+{
+    /**
+     * @inheritDoc
+     */
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        if (!RequestHandler::getInstance()->isACPRequest()) {
+            if (!(80100 <= \PHP_VERSION_ID && \PHP_VERSION_ID <= 80199)) {
+                \header('HTTP/1.1 500 Internal Server Error');
+    
+                throw new NamedUserException(WCF::getLanguage()->get('wcf.global.incompatiblePhpVersion'));
+            }
+        }
+
+        return $handler->handle($request);
+    }
+}
index 3102220cdea6667cba15e10d580a3c86a63704d1..87d223da771847367570723580c3bc5e03add80c 100644 (file)
@@ -9,6 +9,7 @@ use wcf\http\middleware\AddAcpSecurityHeaders;
 use wcf\http\middleware\CheckForEnterpriseNonOwnerAccess;
 use wcf\http\middleware\CheckForExpiredAppEvaluation;
 use wcf\http\middleware\CheckForOfflineMode;
+use wcf\http\middleware\CheckSystemEnvironment;
 use wcf\http\middleware\EnforceCacheControlPrivate;
 use wcf\http\middleware\EnforceFrameOptions;
 use wcf\http\Pipeline;
@@ -76,8 +77,6 @@ final class RequestHandler extends SingletonFactory
 
             $psrRequest = ServerRequestFactory::fromGlobals();
 
-            $this->checkSystemEnvironment();
-
             // build request
             $this->buildRequest($application);
 
@@ -85,6 +84,7 @@ final class RequestHandler extends SingletonFactory
                 new AddAcpSecurityHeaders(),
                 new EnforceCacheControlPrivate(),
                 new EnforceFrameOptions(),
+                new CheckSystemEnvironment(),
                 new CheckForEnterpriseNonOwnerAccess(),
                 new CheckForExpiredAppEvaluation(),
                 new CheckForOfflineMode(),
@@ -105,19 +105,6 @@ final class RequestHandler extends SingletonFactory
         }
     }
 
-    private function checkSystemEnvironment()
-    {
-        if ($this->isACPRequest()) {
-            return;
-        }
-
-        if (!(80100 <= PHP_VERSION_ID && PHP_VERSION_ID <= 80199)) {
-            \header('HTTP/1.1 500 Internal Server Error');
-
-            throw new NamedUserException(WCF::getLanguage()->get('wcf.global.incompatiblePhpVersion'));
-        }
-    }
-
     /**
      * Builds a new request.
      *