‪TYPO3CMS  10.4
PrepareTypoScriptFrontendRendering.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\MiddlewareInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
26 
34 class ‪PrepareTypoScriptFrontendRendering implements MiddlewareInterface
35 {
39  protected ‪$controller;
40 
44  protected ‪$timeTracker;
45 
47  {
48  $this->controller = ‪$controller;
49  $this->timeTracker = ‪$timeTracker;
50  }
51 
59  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
60  {
61  // as long as TSFE throws errors with the global object, this needs to be set, but
62  // should be removed later-on once TypoScript Condition Matcher is built with the current request object.
63  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
64  // Get from cache
65  $this->timeTracker->push('Get Page from cache');
66  // Locks may be acquired here
67  $this->controller->getFromCache($request);
68  $this->timeTracker->pull();
69  // Get config if not already gotten
70  // After this, we should have a valid config-array ready
71  $this->controller->getConfigArray($request);
72 
73  // Setting language and locale
74  $this->timeTracker->push('Setting language');
75  $this->controller->settingLanguage($request);
76  $this->timeTracker->pull();
77 
78  // Convert POST data to utf-8 for internal processing if metaCharset is different
79  if ($this->controller->metaCharset !== 'utf-8' && $request->getMethod() === 'POST') {
80  $parsedBody = $request->getParsedBody();
81  if (is_array($parsedBody) && !empty($parsedBody)) {
82  $this->‪convertCharsetRecursivelyToUtf8($parsedBody, $this->controller->metaCharset);
83  $request = $request->withParsedBody($parsedBody);
84  }
85  }
86  return $handler->handle($request);
87  }
88 
95  protected function ‪convertCharsetRecursivelyToUtf8(&$data, string $fromCharset)
96  {
97  foreach ($data as $key => $value) {
98  if (is_array($data[$key])) {
99  $this->‪convertCharsetRecursivelyToUtf8($data[$key], $fromCharset);
100  } elseif (is_string($data[$key])) {
101  $data[$key] = mb_convert_encoding($data[$key], 'utf-8', $fromCharset);
102  }
103  }
104  }
105 }
‪TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering\__construct
‪__construct(TypoScriptFrontendController $controller, TimeTracker $timeTracker)
Definition: PrepareTypoScriptFrontendRendering.php:44
‪TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering
Definition: PrepareTypoScriptFrontendRendering.php:35
‪TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering\$timeTracker
‪TimeTracker $timeTracker
Definition: PrepareTypoScriptFrontendRendering.php:42
‪TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: PrepareTypoScriptFrontendRendering.php:57
‪TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering\$controller
‪TypoScriptFrontendController $controller
Definition: PrepareTypoScriptFrontendRendering.php:38
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:18
‪TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering\convertCharsetRecursivelyToUtf8
‪convertCharsetRecursivelyToUtf8(&$data, string $fromCharset)
Definition: PrepareTypoScriptFrontendRendering.php:93
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\TimeTracker\TimeTracker
Definition: TimeTracker.php:30