Skip to content
Snippets Groups Projects
Commit 75b84cfb authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Revert "Move frontend pre-process functionality to PSR-15 middleware"

This reverts commit a1f5a232
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: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent a1f5a232
Branches
Tags
No related merge requests found
......@@ -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();
......
......@@ -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
*/
......
<?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);
}
}
<?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);
}
}
<?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'
]
]
]
];
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment