Add `\wcf\http\Helper`
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 8 Aug 2022 09:38:18 +0000 (11:38 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 8 Aug 2022 09:39:12 +0000 (11:39 +0200)
wcfsetup/install/files/lib/http/Helper.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/http/Helper.class.php b/wcfsetup/install/files/lib/http/Helper.class.php
new file mode 100644 (file)
index 0000000..6dec16e
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+namespace wcf\http;
+
+use Psr\Http\Message\ServerRequestInterface;
+
+/**
+ * Provides various helper methods for PSR-7/PSR-15 request processing.
+ *
+ * @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
+ * @since   6.0
+ */
+final class Helper
+{
+    /**
+     * Returns whether the request's 'x-requested-with' header is equal
+     * to 'XMLHttpRequest'.
+     */
+    public static function isAjaxRequest(ServerRequestInterface $request): bool
+    {
+        return $request->getHeaderLine('x-requested-with') === 'XMLHttpRequest';
+    }
+
+    /**
+     * Forbid creation of Helper objects.
+     */
+    private function __construct()
+    {
+        // does nothing
+    }
+}