[TASK] Revert "Move frontend pre-process functionality to PSR-15 middleware" 42/55542/2
authorBenni Mack <benni@typo3.org>
Sat, 3 Feb 2018 22:27:31 +0000 (23:27 +0100)
committerBenni Mack <benni@typo3.org>
Sat, 3 Feb 2018 22:42:53 +0000 (23:42 +0100)
This reverts commit a1f5a2320cdcf50bf4e5670a191baa116a550310
due to author conflicts.

https://review.typo3.org/#/c/55537/

Change-Id: Ie6003a41e75d395a1214904ecce8994ec63ac798
Resolves: #83766
Reverts: #83785
Releases: master
Reviewed-on: https://review.typo3.org/55542
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/Http/EidRequestHandler.php
typo3/sysext/frontend/Classes/Http/RequestHandler.php
typo3/sysext/frontend/Classes/Middleware/PreprocessRequestHook.php [deleted file]
typo3/sysext/frontend/Classes/Middleware/TimeTrackerInitialization.php [deleted file]
typo3/sysext/frontend/Configuration/RequestMiddlewares.php [deleted file]

index f9e7b07..34e3b47 100644 (file)
@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Http\Dispatcher;
 use TYPO3\CMS\Core\Http\NullResponse;
 use TYPO3\CMS\Core\Http\RequestHandlerInterface;
 use TYPO3\CMS\Core\Http\Response;
+use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -90,6 +91,19 @@ class EidRequestHandler implements RequestHandlerInterface, PsrRequestHandlerInt
      */
     public function handle(ServerRequestInterface $request): ResponseInterface
     {
+        // Starting time tracking
+        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
+
+        /** @var TimeTracker $timeTracker */
+        $timeTracker = GeneralUtility::makeInstance(TimeTracker::class, ($request->getCookieParams()[$configuredCookieName] ? true : false));
+        $timeTracker->start();
+
+        // Hook to preprocess the current request
+        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] ?? [] as $hookFunction) {
+            $hookParameters = [];
+            GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
+        }
+
         // Remove any output produced until now
         $this->bootstrap->endOutputBufferingAndCleanPreviousOutput();
 
index b8fbb08..5390816 100644 (file)
@@ -98,8 +98,14 @@ class RequestHandler implements RequestHandlerInterface, PsrRequestHandlerInterf
     {
         $response = null;
         $this->request = $request;
-        // Fetch the initialized time tracker object
-        $this->timeTracker = GeneralUtility::makeInstance(TimeTracker::class);
+        $this->initializeTimeTracker();
+
+        // Hook to preprocess the current request:
+        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] ?? [] as $hookFunction) {
+            $hookParameters = [];
+            GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
+        }
+
         $this->initializeController();
 
         if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force']
@@ -324,6 +330,18 @@ class RequestHandler implements RequestHandlerInterface, PsrRequestHandlerInterf
         }
     }
 
+    /**
+     * Timetracking started depending if a Backend User is logged in
+     */
+    protected function initializeTimeTracker()
+    {
+        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
+
+        /** @var TimeTracker timeTracker */
+        $this->timeTracker = GeneralUtility::makeInstance(TimeTracker::class, ($this->request->getCookieParams()[$configuredCookieName] ? true : false));
+        $this->timeTracker->start();
+    }
+
     /**
      * Creates an instance of TSFE and sets it as a global variable
      */
diff --git a/typo3/sysext/frontend/Classes/Middleware/PreprocessRequestHook.php b/typo3/sysext/frontend/Classes/Middleware/PreprocessRequestHook.php
deleted file mode 100644 (file)
index 0fafd19..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-declare(strict_types = 1);
-namespace TYPO3\CMS\Frontend\Middleware;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
-use Psr\Http\Server\MiddlewareInterface;
-use Psr\Http\Server\RequestHandlerInterface;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/**
- * Calls a hook before processing a request for the TYPO3 Frontend.
- *
- * @internal
- */
-class PreprocessRequestHook implements MiddlewareInterface
-{
-
-    /**
-     * Hook to preprocess the current request
-     *
-     * @param ServerRequestInterface $request
-     * @param RequestHandlerInterface $handler
-     * @return ResponseInterface
-     */
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
-    {
-        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] ?? [] as $hookFunction) {
-            $hookParameters = [];
-            GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
-        }
-        return $handler->handle($request);
-    }
-}
diff --git a/typo3/sysext/frontend/Classes/Middleware/TimeTrackerInitialization.php b/typo3/sysext/frontend/Classes/Middleware/TimeTrackerInitialization.php
deleted file mode 100644 (file)
index a8b953e..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-declare(strict_types = 1);
-namespace TYPO3\CMS\Frontend\Middleware;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
-use Psr\Http\Server\MiddlewareInterface;
-use Psr\Http\Server\RequestHandlerInterface;
-use TYPO3\CMS\Core\TimeTracker\TimeTracker;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/**
- * Initializes the time tracker (singleton) for the whole TYPO3 Frontend
- *
- * @internal
- */
-class TimeTrackerInitialization implements MiddlewareInterface
-{
-    /**
-     * Starting time tracking (by setting up a singleton object)
-     *
-     * @param ServerRequestInterface $request
-     * @param RequestHandlerInterface $handler
-     * @return ResponseInterface
-     */
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
-    {
-        $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
-        GeneralUtility::makeInstance(
-            TimeTracker::class,
-            $request->getCookieParams()[$configuredCookieName] ? true : false
-        )->start();
-        return $handler->handle($request);
-    }
-}
diff --git a/typo3/sysext/frontend/Configuration/RequestMiddlewares.php b/typo3/sysext/frontend/Configuration/RequestMiddlewares.php
deleted file mode 100644 (file)
index eff6fee..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-/**
- * An array consisting of implementations of middlewares for a middleware stack to be registered
- *
- *  'stackname' => [
- *      'middleware-identifier' => [
- *         'target' => classname or callable
- *         'before/after' => array of dependencies
- *      ]
- *   ]
- */
-return [
-    'frontend' => [
-        'typo3/cms-frontend/preprocessing' => [
-            'target' => \TYPO3\CMS\Frontend\Middleware\PreprocessRequestHook::class,
-        ],
-        'typo3/cms-frontend/timetracker' => [
-            'target' => \TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization::class,
-            'after' => [
-                'typo3/cms-frontend/preprocessing'
-            ]
-        ]
-    ]
-];